ios - watchOS 2 上的钥匙串(keychain)访问不适用于实际 watch

标签 ios watchkit keychain watchos-2

我在 Apple 开发者论坛中读到,与 watchOS 1 不同,watchOS 2 不与手机应用程序共享其钥匙串(keychain),所以棒!!默认情况下不启用钥匙串(keychain)共享,我们必须为此采取解决方法。

好吧,说到我的问题,我试图使用 git 库在运行最新测试版 (beta4) 的实际 watch 设备上运行一个非常基本的钥匙串(keychain)访问程序 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")
     }

在模拟器上它的工作方式就像一个魅力,但当我尝试在实际 watch 上运行相同的功能时,它给我一个状态代码-34018

没有关于此错误代码的公开文档,但我做了一些挖掘发现它是

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

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

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

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

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 中修复。

最佳答案

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

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

相关文章:

ios - WatchConnectivity - 使用 sendMessage

swift +锁匠: Not storing value

ios - Flutter firebase_auth 中的无效应用程序凭据/ token 不匹配

ios - WatchKit 定时器结束时的函数

ios - libc++abi.dylib : terminating with uncaught exception of type NSException (lldb) : Drop Down Menu

ios - 只能在 Xcode 模拟器中加载 watch 应用程序或 Phone 应用程序

ios - 手动更改 $(AppIdentifierPrefix) 属性?

ios - 在钥匙串(keychain)中找不到有效的 iOS 代码签名 key

ios - 使用 SwiftUI 和 MapKit 检索用户当前位置

iphone - 当 webview 大于屏幕时,将 UIWebview 内容转换为 UIImage