1

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

Sachintha Udara
  • 635
  • 1
  • 7
  • 22
  • 1
    I don't see the need to bridge it to `NSData`. Try using the CoreFoundation methods [`CFDataGetBytePtr()`](https://developer.apple.com/documentation/corefoundation/1543330-cfdatagetbyteptr?language=objc) and [`CFDataGetLength()`](https://developer.apple.com/documentation/corefoundation/1541728-cfdatagetlength?language=objc) instead and **don't forget to release it** as it looks like you have a leak as it stands. – trojanfoe Sep 27 '19 at 06:51
  • 1
    Seems to be the change of "description" method in NSData. You are doing at some point that and it fails. Cf. https://twitter.com/nshipster/status/1173657903070203905 – Larme Sep 27 '19 at 08:30
  • Yes, you correct NSData doing some new thing in XCode 11 – Sachintha Udara Sep 27 '19 at 09:21
  • Found a solution from this : https://stackoverflow.com/questions/8798725/get-device-token-for-push-notification?answertab=active#tab-top – Sachintha Udara Sep 27 '19 at 10:00

1 Answers1

2

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];
Tommy Leong
  • 2,509
  • 6
  • 30
  • 54