So, i've been looking for a solution for a couple days with no luck so i figured id post here. So in my mobile app users will not "register" in the typical sense rather their account will have a unique id.
So the problem is knowing which user is which and keeping their data the same regardless if they switch to a new device, restore from backup etc.
For IOS i solved this problem by using their iCloud unique identifier. i make an api call to get their id and check my backend to see if they already have an account. (Obviously i can't account for someone who purposely signs out just to mess with it. Some edge cases aren't worth fighting over.) Here is the api call to iCloud written in swift,
CKContainer.defaultContainer().fetchUserRecordIDWithCompletionHandler({ (recordID, error) -> Void in
dispatch_async(dispatch_get_main_queue()) { () -> Void in
if error == nil
{
if recordID != nil
{
self.rid = recordID!.recordName
let json = ["user":self.rid]
networkController.newUser(json)
}
else
{
// Just a random string
self.rid = randomID()
let json = ["userID":self.rid]
networkController.newUser(json)
}
}
else
{
MBProgressHUD.hideHUDForView(self.view, animated: true)
let alert = UIAlertController(title: "Uh Oh", message: error!.localizedDescription, preferredStyle: .Alert)
let okayAction = UIAlertAction(title: "Okay", style: .Cancel, handler: nil)
alert.addAction(okayAction)
self.presentViewController(alert, animated: true, completion: nil)
}
}
})
This guarantees a unique CloudKit record when a user is signed into their iCloud account so no need to create a new account if restoring a backup or getting a new device.
My question is does Google/Android have something similar that's not necessarily their email address or anything personal.Because android devices are cheap and usually swapped frequently i wanted a way to be able to keep a users data in sync. Any help or feedback is greatly appreciated.