Why does NSURLCredentialStorage no longer works since the update to xcode 8??

I was using it to auto login and since that update it does not work. And how a waste of time to check the debugg consloe with all these useless informations!!

Replies

Why does NSURLCredentialStorage no longer works since the update to xcode 8??

It’s impossible to answer this without more information about what you’re trying to do with this class. To start, what platform are you on?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi. And sorry for the lack of infos.

So, i am coding for ios using objective C.

I am using this class to log in and out while saveing the credentials to autologin the user when he did not log out.

Here is the snipets for you to have an idea.

On the log in, it seems working but when i exit the viewcontroller and come back, the credentials should be checked and applied.

//LOG IN//


NSURLProtectionSpace *loginProtectionSpace = [[NSURLProtectionSpace alloc]
                                                     initWithHost:@"https:***.com"
                                                     port: 443
                                                     protocol:NSURLProtectionSpaceHTTP
                                                     realm:nil
                                                     authenticationMethod:NSURLAuthenticationMethodDefault];
       
         NSURLCredential *credential = [NSURLCredential credentialWithUser:_userNameLogInPlayFab.text password:_passwordLoginPlayFab.text persistence:NSURLCredentialPersistencePermanent];
       
         [[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential forProtectionSpace:loginProtectionSpace];
         NSLog(@"User connected:%@ with password:%@", credential.user, credential.password);
      

The log out crashes the app and highlights these lines when before the update, it was working perfectly.

//LOG OUT// 


[[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:loginProtectionSpace];
    NSLog(@"Credential removed.");

In general, I don’t recommend that you manually stash credentials in NSURLCredentialStorage. It’s much better to respond to authentication challenges via the NSURL{Session,Connection} delegate callbacks.

However, this should work. Let’s start with the crash. You wrote:

The log out crashes the app …

What are the symptoms of this crash? If you run without the debugger, the crash should generate a crash log. Please grab that, symbolicate it, and post it here.

Technote 2151 Understanding and Analyzing iOS Application Crash Reports discusses that process in more detail.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo!


I'm running into the same issue. Well, my app doesn't crash but it's not working as I'd expect ever since I upgraded to Xcode 8/Swift 2.3/iOS 10.

This is only happening on the simulator with iOS 10, but it makes me uneasy to merge this into master for all my team to work on.

I managed to strip the responsible code into a 6 lines test. Would you mind taking a look?

https://cl.ly/3f1w34451E0d


Test with iPhone 5s (9.3) > Pass

Test with iPhone 5s (10.0) > Fail

Test with real device (10.0) > Pass


Any ideas what may be happening? Is it safe to use this, does it seem like this is contained in the simulator?


Thanks in advance!

Mariano.

This is only happening on the simulator with iOS 10 …

This probably has the same underlying cause as described in this thread. When you use

NSURLCredentialPersistencePermanent
, the credentials go into the keychain, so your test is only going work if the keychain is working. Fortunately there’s a relatively straightforward workaround, which you’ll find on the above-mentioned thread.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Cool, thanks so much!


Adding the entitlements.plist as suggested on that thread completely fixed my issue.