user1644419
user1644419

Reputation: 25

How can i get the UUID of my IPHONE in an application?

I am developing an application with external databases. For this motive, I have to save an uuid the only identifier for every user who registers. This way, it will differ if the user is a new user or is a user already registered in the application. I create a new uuid with this:

NSUUID *uuid = [NSUUID UUID];

And i save that at external databases with the username. How do I obtain this information when the user enter again to the application? Have I to save it in some place of the device?

Upvotes: 0

Views: 612

Answers (1)

FluffulousChimp
FluffulousChimp

Reputation: 9185

For one, you could could use NSUserDefaults

To cache uuid:

[[NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"userIDKey"];

To retrieve uuid:

NSString *uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"userIDKey"];

Note that using the NSUUID class restricts you to an iOS target of iOS 6.0+. There are other ways to generate a UUID < iOS 6.0, e.g.

+ (NSString*)stringWithUUID {
    CFUUIDRef uuidObj = CFUUIDCreate(nil);
    NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj);
    CFRelease(uuidObj);
    return uuidString;
}

Upvotes: 1

Related Questions