Browse Source

Merge pull request #33 from kishikawakatsumi/fix_8_0

Workaround updating Touch ID protected item in iOS 8.0 (not 8.1+)
kishikawa katsumi 10 years ago
parent
commit
c3ec78627b
1 changed files with 12 additions and 1 deletions
  1. 12 1
      Lib/KeychainAccess/Keychain.swift

+ 12 - 1
Lib/KeychainAccess/Keychain.swift

@@ -185,6 +185,8 @@ public class Keychain {
     private let options: Options
     private let options: Options
     
     
     private let NSFoundationVersionNumber_iOS_7_1 = 1047.25
     private let NSFoundationVersionNumber_iOS_7_1 = 1047.25
+    private let NSFoundationVersionNumber_iOS_8_0 = 1140.11
+    private let NSFoundationVersionNumber_iOS_8_1 = 1141.1
     private let NSFoundationVersionNumber10_9_2 = 1056.13
     private let NSFoundationVersionNumber10_9_2 = 1056.13
     
     
     // MARK:
     // MARK:
@@ -367,7 +369,16 @@ public class Keychain {
                 println("error:[\(error.code)] \(error.localizedDescription)")
                 println("error:[\(error.code)] \(error.localizedDescription)")
                 return error
                 return error
             } else {
             } else {
-                status = SecItemUpdate(query, attributes)
+                if status == errSecInteractionNotAllowed && floor(NSFoundationVersionNumber) <= floor(NSFoundationVersionNumber_iOS_8_0) {
+                    var error = remove(key)
+                    if error != nil {
+                        return error
+                    } else {
+                        return set(value, key: key)
+                    }
+                } else {
+                    status = SecItemUpdate(query, attributes)
+                }
                 if status != errSecSuccess {
                 if status != errSecSuccess {
                     return securityError(status: status)
                     return securityError(status: status)
                 }
                 }