Hi,I'm crurently unable to access my app keychain after a long search these are the steps that I've tryed so farFirst of All I'm running on "real" devices not in simulators1. Key chain is enabled for a group, in here I will go for this group "appbundle.sharedkeychain" and the app prefix I'll say that's "1A2B3C4D5E"2. The keychain code is currently implemented on a Framework3. The Framework is a Pod that I've downloaded and tweaked so that worked with a shared keychain witch so far I was unable to.So I created a variable called kSAAGroup witch contains the following string "1A2B3C4D5E.appbundle.sharedkeychain"In the addKeychainFunction I have the following codeprivate func addKeychainItem(withAttributes attributes: [String: AnyObject]) throws -> Data {
var mutableAttributes = attributes
mutableAttributes[kSecClass as String] = kSecClassGenericPassword
mutableAttributes[kSecReturnPersistentRef as String] = kCFBooleanTrue
mutableAttributes[kSecAttrSynchronizable as String] = kCFBooleanTrue
mutableAttributes[kSecAttrAccessible as String] = kSecAttrAccessibleAlways
mutableAttributes[kSecAttrAccessGroup as String] = kSAAGroup as AnyObject?
/
/
if mutableAttributes[kSecAttrAccount as String] == nil {
mutableAttributes[kSecAttrAccount as String] = UUID().uuidString as NSString
}
var result: AnyObject?
let resultCode: OSStatus = withUnsafeMutablePointer(to: &result) {
SecItemAdd(mutableAttributes as CFDictionary, $0)
}
guard resultCode == errSecSuccess else {
throw Keychain.Error.systemError(resultCode)
}
guard let persistentRef = result as? Data else {
throw Keychain.Error.incorrectReturnType
}
return persistentRef
}And to retrieve all the keychain itemsprivate func allKeychainItems() throws -> [NSDictionary] {
let queryDict: [String : AnyObject] = [
kSecClass as String: kSecClassGenericPassword,
kSecMatchLimit as String: kSecMatchLimitAll,
kSecReturnPersistentRef as String: kCFBooleanTrue,
kSecReturnAttributes as String: kCFBooleanTrue,
kSecReturnData as String: kCFBooleanTrue,
kSecAttrSynchronizable as String: kCFBooleanTrue,
kSecAttrAccessible as String: kSecAttrAccessibleAlways,
kSecAttrAccessGroup as String: kSAAGroup as AnyObject,
]
var result: AnyObject?
let resultCode = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(queryDict as CFDictionary, $0)
}
if resultCode == errSecItemNotFound {
/
return []
}
guard resultCode == errSecSuccess else {
throw Keychain.Error.systemError(resultCode)
}
guard let keychainItems = result as? [NSDictionary] else {
throw Keychain.Error.incorrectReturnType
}
return keychainItems
}I add the item to the keychain on the iPhone and if I close the app and reopen all the items are still there, so I assume everything it's working on the local level, I can add, delete, update and fetch all items.Now on the watchOS I get nothing, as if the keychain is empty.Any ideas?
10
1
6.0k