8

I want to store access token to keychain. But i got the error: Couldn't add the Keychain Item.'

I checked some posts on stackoverflow like: Storing email in keychain impossible (KeychainItemWrapper)

MyCode:

let a = NSKeyedArchiver.archivedData(withRootObject: "980a872c17a075367357e25e88c1c0476417092a")
let keyWrapper = KeychainItemWrapper.init(identifier: "23123123", accessGroup: nil)
keyWrapper?.setObject(a, forKey: kSecValueData)
  1. I tried add this

    keyWrapper?.setObject(kSecAttrAccessible, forKey: kSecAttrAccessible)
    
  2. Change kSecValueData to kSecAttrGeneric

I am running Xcode 8 with swift 3.0. Any hints thank you!

EDIT===========================

Viruss mca's answer turn on Share keychain entitlement just work once for me : (

Community
  • 1
  • 1
William Hu
  • 15,423
  • 11
  • 100
  • 121
  • Duplicate of http://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator? – Martin R Sep 21 '16 at 12:13

2 Answers2

27

I have recently face this issue with Xcode 8.

To solve the issue You have to add the "Share keychain entitlement" to Xcode capabilities.

enter image description here

There are many users who faced this issue.

Ref: https://forums.developer.apple.com/thread/60617

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
-2

OK, after struggle a long time i found i my Apple account was expired before i update to Xcode8. I solved it by removed my account then login again. And only for device not simulator.

William Hu
  • 15,423
  • 11
  • 100
  • 121