Search code examples
iosiphoneipadios-app-groupuickeychainstore

Can we access keychain items that are saved before enabling keychain sharing from app sharing same app group?


Can we access keychain items that are saved before enabling keychain sharing from app sharing same app group? If NO then what could be the best workaround?


Solution

  • Before enabling keychain sharing all keychain items "accessGroup" is (AppIdentifierPrefix).bundleIdentifier, which is changed to (AppIdentifierPrefix).keyChainGroupName after turning it on.

    Workaround is to remove all keychain items by accessing those through keychains.

    AWSUICKeyChainStore *keychain = [AWSUICKeyChainStore keyChainStoreWithService:@"ServiceName"];
    for (NSDictionary *dictionary in keychain.allItems)
        if ([dictionary[@"accessGroup"] isEqualToString:"(AppIdentifierPrefix).bundleIdentifier"])
            [keychain removeItemForKey:dictionary[@"key"]];