0

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.

Andrew Edwards
  • 1,005
  • 1
  • 9
  • 24

1 Answers1

0

Andrew,

I think the answer to your question is here....

Generate a UUID on iOS from Swift

and here ...

http://developer.android.com/reference/java/util/UUID.html

In a word "UUID" is the answer to your question

Community
  • 1
  • 1
user3069232
  • 8,587
  • 7
  • 46
  • 87
  • Ok i see what you're saying. My only question now is with an android uuid how can i determine that a user account already exists if they get a new device? I need something to base it on when the app first launches. With iCloud it's based on their account that they're logged in system wide for App Store and other services. UUID would work only if they never switched to a new device. – Andrew Edwards Apr 13 '16 at 05:14
  • Andrew; I am sorry I am not android man; but a simple IOS fellow. Can you not do something with Google drive perhaps? Google are after all the owners of Android. – user3069232 Apr 13 '16 at 11:26
  • Im not sure, I'm just getting into Android development and id rather not keep users' email. But it looks like i might have to. – Andrew Edwards Apr 13 '16 at 14:59