1

I tried to use SSKeychain to reserve UUID on iOS

and the sample code is below

NSString *retrieveuuid = [SSKeychain passwordForService:@"tempApp" account:@"tempUser"];
if (retrieveuuid == nil) {
    //Generate UUID
    CFUUIDRef cfuud = CFUUIDCreate(kCFAllocatorDefault);
    NSString *uuid = CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
    //save in keychain
    [SSKeychain setPassword:uuid forService:@"tempApp" account:@"tempUser"];
    return uuid;
} else {
    return retrieveuuid;
}

My question is that I run the first app and then generate a UUID, and then run the second app which has the same parameters, so that the retrieveduuid should not be null, then why the second App returns a different UUID? I think that will return the same UUID as first app because I have saved the UUID in the keychain in App1 and try to retrieve it by the same parameters in App2.

Thanks for help

Kuan-Jong Wu
  • 109
  • 2
  • 7

1 Answers1

0

UUID is a Universally Unique IdenTifier. Would be kind of stupid if you got the same in two different apps, wouldn't it? ;)

If you want to share keychains between apps, see this question: How to share keychain data between iOS applications

Community
  • 1
  • 1
Rick
  • 3,240
  • 2
  • 29
  • 53
  • yeah, I know UUID should be different, just wonder why app2 not retrieves app1's UUID because app1 has saved its UUID into keychain and app2 use the same value of parameters. – Kuan-Jong Wu Dec 13 '13 at 08:41
  • 1
    Because apps have sandboxed keychains, just like the filesystem. App 1 can't access the files saved by App 2. The link provides some info about how to share a keychain. – Rick Dec 13 '13 at 08:43