Jeremy Massel
Jeremy Massel

Reputation: 2267

iCloud GUID Across Devices

I'm trying to figure out a way to generate a unique iCloud ID that will be the same across devices. My app stores data in an online database that I would like to tie back to an iCloud id. This gives the nice user experience of not having to deal with logins (since all data is tied to their iCloud account), without being stuck using iCloud's lousy sync. The problem is that as far as I know, there's no API that will give me this kind of ID.

Things I've tried/thought about:

1) NSUbiquitousKeyValueStore

Doesn't work, because the value will get updated "sometime later" i.e. - whenever Apple feels like it.

2) iCloud Document Storage

Same problem as #1, with the added bonus of storing a random file in the device that the user can remove by hand

3) Using [[NSFileManager defaultManager] ubiquityIdentityToken]

Because the Ubiquity Token's bytes are the same for any given login session, I imagined it may be that this may be the case across devices. Not the case

4) Using the Address Book Contact

Seems like it would be unreliable (what happens if they change their main email/phone number/name), plus has the side effect of annoying/freaking out the user at first launch (how do they know I'm not stealing all their contacts?)

5) Rolling my own login system tied to a remote server

This seems to be the only option available, although I'd prefer a better one.

Thanks in advance

Upvotes: 3

Views: 573

Answers (2)

John Scalo
John Scalo

Reputation: 3411

Perhaps this is too late to be useful, but iOS 8 has provided a solution here. From the WWDC 2014 “Intro to CloudKit” session:

So, instead what we do is on a container by container basis we come up with a random ID. This is an identifier that is stable so that is your application no matter what client it's running on talking to this container will get the same identifier, but it's not identifying the user via any personal information. … We've given you enough support that if you wanted to you could implement a login via iCloud flow in your application using the CloudKit framework.

[ Transcription courtesy of http://asciiwwdc.com/2014/sessions/208 ]

To flesh that out a bit more, if your app is provisioned for CloudKit storage then its default container comes with an auto-generated user record representing the currently signed-in iCloud user (if any). The UUID (actually called recordName) associated with this user record is consistent for your app across installs and across devices.

E.g.:

[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
    …
    myiCloudUserID = recordID.recordName;
}];

Upvotes: 9

ImHuntingWabbits
ImHuntingWabbits

Reputation: 3827

There is no persistent unique identifier for iCloud.

Option 5 is your best bet unless you want to do conflict resolution on a sync'd file that uses document storage.

Upvotes: 1

Related Questions