Uniquely identifying an iOS user

Viewed 15708

I'd like to create a user account on the server for new users of an app, but I'd also like to not ask the user to type in anything. Ideally, I'd like this to be automatic, like with Game Center.

But I'm wondering if it's possible. Is there anything I can use to uniquely identify the user? It's highly unlikely that I can find out the user's Apple ID. Also, the device ID uniquely identifies the device, not the user, so it would be useless if the user has more devices...

Is there anything else I can use?

About privacy - I don't want to find out anything behind the user's back. I have absolutely no problem with asking the user for access to their information (and if there is an API that grants me this information, it would be great if the API asks this itself). As Steve Jobs himself said, this is what privacy is all about - forcing apps to ask the user for permission before doing anything with their private data.

10 Answers

Swift3/4+

Using iCloud record ID (CKRecordID). This ID will be unique for iTunes account.

let container = CKContainer.default()
container.fetchUserRecordID() {
    recordID, error in

    if let err = error {
        print(err.localizedDescription)
    }
    else if recID = recordID {
        print("fetched ID \(recID.recordName ?? "NA")")
    }
}

For automatically created records, the ID name string is based on a UUID and is therefore guaranteed to be unique.

Please note that if device doesn’t have an iCloud account, or has an iCloud account with restricted access, this returns CKError.Code.notAuthenticated error

Related