From e560ac705a4c96d8d94a702be83ff81ff08fcb4b Mon Sep 17 00:00:00 2001 From: kishikawa katsumi Date: Thu, 15 Jan 2015 03:33:13 +0900 Subject: [PATCH] Workaround updating Touch ID protected item in iOS 8.0 (not 8.1+) --- Lib/UICKeyChainStore/UICKeyChainStore.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/UICKeyChainStore/UICKeyChainStore.m b/Lib/UICKeyChainStore/UICKeyChainStore.m index 6d44ab0..47d31f6 100644 --- a/Lib/UICKeyChainStore/UICKeyChainStore.m +++ b/Lib/UICKeyChainStore/UICKeyChainStore.m @@ -440,7 +440,7 @@ static NSString *_defaultService; [query removeObjectForKey:(__bridge id)kSecUseNoAuthenticationUI]; } #endif - NSError *unexpectedError; + NSError *unexpectedError = nil; NSMutableDictionary *attributes = [self attributesWithKey:nil value:data error:&unexpectedError]; if (label) { @@ -456,7 +456,14 @@ static NSString *_defaultService; } return NO; } else { - status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)attributes); + + if (status == errSecInteractionNotAllowed && floor(NSFoundationVersionNumber) <= floor(1140.11)) { // iOS 8.0.x + if ([self removeItemForKey:key error:error]) { + return [self setData:data forKey:key label:label comment:comment error:error]; + } + } else { + status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)attributes); + } if (status != errSecSuccess) { if (error) { *error = [self.class securityError:status]; @@ -465,7 +472,7 @@ static NSString *_defaultService; } } } else if (status == errSecItemNotFound) { - NSError *unexpectedError; + NSError *unexpectedError = nil; NSMutableDictionary *attributes = [self attributesWithKey:key value:data error:&unexpectedError]; if (label) { @@ -909,7 +916,7 @@ static NSString *_defaultService; CFTypeRef accessibilityObject = [self accessibilityObject]; if (_authenticationPolicy && accessibilityObject) { if (floor(NSFoundationVersionNumber) > floor(iOS_7_1_or_10_9_2)) { // iOS 8+ or OS X 10.10+ - CFErrorRef securityError; + CFErrorRef securityError = NULL; SecAccessControlRef accessControl = SecAccessControlCreateWithFlags(kCFAllocatorDefault, accessibilityObject, (SecAccessControlCreateFlags)_authenticationPolicy, &securityError); if (securityError) { if (error) {