- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 Apple 开发者论坛上了解到,与 watchOS 1 不同,watchOS 2 不与手机应用程序共享其钥匙串(keychain),所以 bam!!默认情况下不启用钥匙串(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/
我是一名优秀的程序员,十分优秀!