Search code examples
objective-cpush-notificationnsstringios13xcode11

iOS 13 | Xcode 11 | NSData


I am in confusing in iOS 13 with keychain access.

CFDataRef passwordData = NULL;
OSStatus keychainError = noErr;
keychainError = SecItemCopyMatching((__bridge CFDictionaryRef)returnDictionary,
                                        (void *)&passwordData);

NSString *password = [[NSString alloc] initWithBytes:[(__bridge_transfer NSData *)passwordData bytes] length:[(__bridge NSData *)passwordData length] encoding:NSUTF8StringEncoding];

after execute above code segment, password variable value is

{length=32,bytes=0xf3388feaa238e92da01a21fdc477921c...2f021935af7f1883},,,,,,,,

but in iOS 12 and older, I can get expected value for password variable.

And this only happen in xcode 11 with iOS 13

re-edited : This is not related to the keychain, all happen from NSData description method


Solution

  • Apple has made changes the format of description for Foundation objects, which in our case NSData. Belows an the example of the changes:

    // iOS 12
    (deviceToken as NSData).description // "<965b251c 6cb1926d e3cb366f dfb16ddd e6b9086a 8a3cac9e 5f857679 376eab7C>"
    
    // iOS 13
    (deviceToken as NSData).description // "{length = 32, bytes = 0x965b251c 6cb1926d e3cb366f dfb16ddd ... 5f857679 376eab7c }"
    

    For you to get the previous value description, you can use debugDescription.

    Example as below:

    NSString* oldHashValue = [NSString stringWithFormat:@"%@",newHashValue.debugDescription];