KeychainItemWrapper 'Couldn't add the Keychain Item.'
Asked Answered
R

2

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 : (

Raasch answered 21/9, 2016 at 10:34 Comment(1)
Duplicate of #38456971?Antisepsis
F
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

Firenze answered 21/9, 2016 at 10:52 Comment(5)
Hi Viruss, it's interesting. This just work for me once. I enabled it. And still same error now. I tried to add KeyChain Groups string into accessGroup parameter, still no help. Any idea?Raasch
@WilliamHu: where did you get this issue? on device?Firenze
Both simulator and device.Raasch
Sorry just for attention, i canceled the accept answer. Thank you anyway!Raasch
I only see this error in my simulator, on iOS 10 devices it runs fine. I'm very confused.Miltie
R
-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.

Raasch answered 23/9, 2016 at 16:22 Comment(3)
The other answer about the Entitlements should really be the accepted answer.Quinine
Hi @KennyWyland i knew Viruss did provide a good solution, but it doesn't really solve my problem. I have up voted for this answer. Thank you!Raasch
It didn't solve your problem, but was the reason for it, from the answers provided, was the best oneCalypso

© 2022 - 2024 — McMap. All rights reserved.