Evg*_*nii 102 xcode ios ios10 xcode8
更新:此问题已在Xcode 8.2中修复.Keychain在模拟器中工作,无需启用钥匙串共享.
为什么在Xcode 8/iOS 10模拟器中调用函数时总是收到错误-34018 ?SecItemAdd
在Xcode 8中创建一个新的单页iOS应用程序项目.运行以下代码viewDidLoad(或打开此 Xcode项目).
let itemKey = "My key"
let itemValue = "My secretive bee "
// Remove from Keychain
// ----------------
let queryDelete: [String: AnyObject] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: itemKey as AnyObject
]
let resultCodeDelete = SecItemDelete(queryDelete as CFDictionary)
if resultCodeDelete != noErr {
print("Error deleting from Keychain: \(resultCodeDelete)")
}
// Add to keychain
// ----------------
guard let valueData = itemValue.data(using: String.Encoding.utf8) else {
print(" Error saving text to Keychain")
return
}
let queryAdd: [String: AnyObject] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: itemKey as AnyObject,
kSecValueData as String: valueData as AnyObject,
kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlocked
]
let resultCode = SecItemAdd(queryAdd as CFDictionary, nil)
if resultCode != noErr {
print(" Error saving to Keychain: \(resultCode).")
} else {
print(" Saved to keychain successfully.")
}
Run Code Online (Sandbox Code Playgroud)
项目已添加到Keychain.
函数SecItemAdd返回以下错误代码:-34018.
Xcode版本8.1(8B62),macOS Sierra 10.12.1.
自从Beta 2在iOS 10模拟器中进行测试时,总是出现在Xcode 8中.
在iOS 9.3模拟器中进行测试时,Xcode 8中不会出现这种情况.
https://dl.dropboxusercontent.com/u/11143285/2016/07/KeychainBugDemo.zip
雷达:https://openradar.appspot.com/27422249
Apple开发者论坛:https://forums.developer.apple.com/message/179846
此问题与以下帖子不同,因为它在Xcode 8中一致地发生.SecItemAdd和SecItemCopyMatching返回错误代码-34018(errSecMissingEntitlement)
Dey*_*ton 183
通过将Keychain Access Groups添加到Entitlements文件,我能够在我的应用程序中解决此问题.我在测试应用程序的Capabilities部分打开了Keychain Sharing开关,它也适用于我.

要添加到权利的项目:
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.evgenii.KeychainBugDemo</string>
</array>
Run Code Online (Sandbox Code Playgroud)
我只在macOS Sierra(10.12)上试过这个,所以我不确定它是否适用于10.11.5.
Tia*_*ida 17
在Xcode 8.1 GM发行说明中, Apple承认了这个问题并提出了一个更清晰的解决方法:
如果您的权利文件不包含应用程序标识符权利的值,则Keychain API可能无法在Simulator中运行.(28338972)解决方法:将用户定义的构建设置添加到名为ENTITLEMENTS_REQUIRED的目标,并将值设置为YES.这将导致Xcode在构建时自动插入应用程序标识符权利.
请注意,根据我的尝试,它只适用于Xcode 8.1.虽然文本可能会误导您进入构建设置,但您需要做的是将其添加到您的方案中的环境变量中.
Xcode 8.2将解决这个问题:
已在Xcode 8.2 beta中解决 - IDE Keychain API在Simulator中正常运行.(28338972)
小智 5
我在使用电子邮件签名,创建新用户或使用firebase注销时遇到错误.
错误是:
firauth错误域代码17995
我在测试应用程序的Capabilities部分打开了Keychain Sharing开关,它也适用于我.
| 归档时间: |
|
| 查看次数: |
29091 次 |
| 最近记录: |