watchOS 2上的钥匙串访问不适用于实际的手表

时间:2015-07-29 17:36:00

标签: ios watchkit keychain watch-os-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中修复。

1 个答案:

答案 0 :(得分:3)

Apple在最近的watchOS 2 beta 5中修正了问题。