1

I am trying to write data to the iCloud Keychain and have it replicate across devices using the same Apple ID.

If I install an app and call the following code, write an entry, and tun read, I see the data being read back to log on the current device.

However, if I install the same code on another device using same Apple ID, with iCloud/keychain switched on, I don't see the data if I attempt to read from keychain on that device.

I have tried enabling icloud and keychain sharing in capabilities to no avail.

Could someone point me in the right direction please?

-(void)writekc{
    KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"AppName" accessGroup:nil];
    [keychainItem setObject:@"password" forKey:(__bridge id)(kSecValueData)];
    [keychainItem setObject:@"username" forKey:(__bridge id)(kSecAttrAccount)];
}

-(void)readkc{
    KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"AppName" accessGroup:nil];
    NSString *password = [keychainItem objectForKey:(__bridge id)(kSecValueData)];
    NSString *username = [keychainItem objectForKey:(__bridge id)(kSecAttrAccount)];
    NSLog(@"Password:%@, User:%@",password,username);
 }
NeilMortonNet
  • 1,500
  • 4
  • 16
  • 36
  • You need to make sure that the wrapper code you are calling adds kSecAttrSynchronizable true to the dictionary passed to the secItem calls – Paulw11 Jun 02 '14 at 13:28
  • 1
    @Paulw11 I have just added [keychainItem setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)(kSecAttrSynchronizable)]; to the write code above, but get an assertion error. – NeilMortonNet Jun 02 '14 at 13:40
  • use (__bridge id)(kSecAttrSynchronizableAny – obogz_mobile Jan 22 '16 at 09:43

1 Answers1

1

In the end I have used SSKeyChain which has sync capability built in.

NeilMortonNet
  • 1,500
  • 4
  • 16
  • 36