2

我在 Apple 开发者论坛上读到,与 watchOS 1 不同,watchOS 2 不与手机应用程序共享其钥匙串,所以 bam!默认情况下未启用钥匙串共享,我们必须为此做一个解决方法。

好的,来解决我的问题,我试图在运行最新测试版(beta4)的实际手表设备上运行一个非常基本的钥匙串访问程序,使用 git 库https://github.com/jrendel/SwiftKeychainWrapper

  let saveSuccessful: Bool = KeychainWrapper.setString("keychainData", forKey: "ImportantKeychainData")

  if saveSuccessful{
       let retrievedString: String? = KeychainWrapper.stringForKey("ImportantKeychainData")
       print(retrievedString)
     }
     else
     {
       print("unable to write keychain data")
     }

在模拟器上它就像一个魅力但是当我尝试在实际手表上运行它时它给了我一个状态代码-34018

没有关于这个错误代码的公开文档,但我做了一点挖掘发现它原来是

errSecMissingEntitlement     = -34018,  /* Internal error when a required entitlement isn't present. */

来源: http: //opensource.apple.com/source/Security/Security-55471/sec/Security/SecBasePriv.h

实际上,我花了一整天的时间对此进行了大量研究,人们向我指出了各个方向,例如内存问题、权利、配置文件问题、钥匙串中的错误等。

这里的问题是,大多数报告此问题的开发人员并没有像我在每次运行应用程序时都得到它一样,他们只在某些地方有它,比如当应用程序在后台时等等。总而言之,

1. I tried the same piece of code on iOS 9 beta 4 and it worked well on the phone.

2. The same code works well on the watch simulator.

3. The same code does not work on watchOS beta 4 returns -34018 continuously on the device but works well on the simulator.

4. All this testing is done using free provisioning introduced from Xcode 7, entitlements were added to the phone app and the watch extension, keychain sharing was enabled, app groups was enabled.

我的问题是

1. Am I missing something here that I have to do with the device keychain that I am supposedly doing it wrong?

2. Is there an issue with free provisioning?

3. Is there an issue with the keychain perhaps??

任何帮助表示赞赏。

仅供参考,我还尝试了 Apple 的 KeychainItemWrapper,海关代码直接与 SecItem 方法对话,结果没有任何结果。

更新,我也试过了,它像往常一样失败

let storableString:NSString = "keychain in watchos is working with simple code"  
  let query : [NSString : AnyObject] = [  
            kSecClass : kSecClassGenericPassword,  
            kSecAttrService : "WatchService",  
            kSecAttrLabel : "KeychainData",  
            kSecAttrAccount : "SecureData",  
            kSecValueData : storableString.dataUsingEncoding(NSUTF8StringEncoding)!  
        ]  
  let result = SecItemAdd(query, nil)  
  print(result)  

更新 2:问题已在 watchOS2 beta 5 中得到修复。

4

1 回答 1

3

Apple 在最近的 watchOS 2 beta 5 中修复了这个问题。

于 2015-08-07T16:47:17.063 回答