अद्यतन : यह मुद्दा Xcode 8.2 में तय किया गया है। किचेन शेयरिंग को सक्षम किए बिना सिम्युलेटर में काम करता है।
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.")
}
अपेक्षित परिणाम
आइटम किचेन में जोड़ा जाता है।
वास्तविक परिणाम
फ़ंक्शन SecItemAdd निम्न त्रुटि कोड लौटाता है -34018:।
संस्करण
Xcode संस्करण 8.1 (8B62), macOS सिएरा 10.12.1।
विन्यास
हमेशा आईओएस 10 सिम्युलेटर में परीक्षण करते समय बीटा 2 के बाद से हमेशा 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 (इरेटेकमिसिंगईंटिफिलमेंट)




