123FLO321
123FLO321

Reputation: 862

Unique Identifier for iCloud / CloudKit User

Is there a better solution (then the possible workaround below) to get an UUID for a iCloud / CloudKit User?
So it's possible to detect if the user already did something (on a different device) with same iCloud account.

Possible workaround:

Upvotes: 1

Views: 1258

Answers (1)

123FLO321
123FLO321

Reputation: 862

I found a possible solution:

Swift 2

CKContainer.default().fetchUserRecordID(completionHandler: { (recordID: CKRecordID?, error: NSError?) in
    print(recordID?.recordName) // UUID String for iCloud user
})

Swift 3

CKContainer.default().fetchUserRecordID(completionHandler: { (recordID: CKRecordID?, error: Error?) in
    print(recordID?.recordName) // UUID String for iCloud user
})

This id is the same across all devices using the same iCloud Account.

Upvotes: 7

Related Questions