我在Apple开发人员论坛上了解到,与watchOS 1不同,watchOS 2不会与手机应用程序共享其钥匙串!默认情况下,钥匙串共享未启用。为此,我们必须采取一种解决方法。

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

  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

没有关于此错误代码的 public 文档,但是我做了一些挖掘,发现原来是
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中已解决问题。

最佳答案

苹果已在最近的watchOS 2 beta 5中修复了该问题。

关于ios - watchOS 2上的钥匙串(keychain)访问在实际 watch 上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31707375/

10-12 03:04