SecItemAdd always returns error -34018 in Xcode 8 in iOS 10 simulator -


update: issue has been fixed in xcode 8.2. keychain works in simulator without enabling keychain sharing.

why always receiving error -34018 when calling secitemadd function in xcode 8 / ios 10 simulator?

steps reproduce

create new single page ios app project in xcode 8. run following code in viewdidload (or open this xcode project).

let itemkey = "my key" let itemvalue = "my secretive bee 🐝"  // remove keychain // ----------------  let querydelete: [string: anyobject] = [   ksecclass string: ksecclassgenericpassword,   ksecattraccount string: itemkey anyobject ]  let resultcodedelete = secitemdelete(querydelete cfdictionary)  if resultcodedelete != noerr {   print("error deleting keychain: \(resultcodedelete)") }   // add keychain // ----------------  guard let valuedata = itemvalue.data(using: string.encoding.utf8) else {   print("🐣🐣🐣🐣🐣🐣🐣🐣🐣🐣 error saving text keychain")   return }  let queryadd: [string: anyobject] = [   ksecclass string: ksecclassgenericpassword,   ksecattraccount string: itemkey anyobject,   ksecvaluedata string: valuedata anyobject,   ksecattraccessible string: ksecattraccessiblewhenunlocked ]  let resultcode = secitemadd(queryadd cfdictionary, nil)  if resultcode != noerr {   print("🐝🐝🐝🐝🐝🐝🐝🐝🐝 error saving keychain: \(resultcode).") } else {   print("🍀🍀🍀🍀🍀🍀🍀🍀🍀 saved keychain successfully.") } 

expected results

item added keychain.

actual results

function secitemadd returns following error code: -34018.

version

xcode version 8.1 (8b62), macos sierra 10.12.1.

configuration

always occurs in xcode 8 since beta 2 when testing in ios 10 simulator.

does not occur in xcode 8 when testing in ios 9.3 simulator.

demo

https://dl.dropboxusercontent.com/u/11143285/2016/07/keychainbugdemo.zip

references

radar: https://openradar.appspot.com/27422249

apple developer forums: https://forums.developer.apple.com/message/179846

this issue different following post because occurs consistently in xcode 8. secitemadd , secitemcopymatching returns error code -34018 (errsecmissingentitlement)

i able work around in app adding keychain access groups entitlements file. turned on keychain sharing switch in capabilities section in test app, , working me well.

screenshot of turning on switch

item add entitlements:

<key>keychain-access-groups</key> <array>     <string>$(appidentifierprefix)com.evgenii.keychainbugdemo</string> </array> 

i have tried on macos sierra (10.12), i'm not sure if work on 10.11.5.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -