iOS Question CFUUID as safe userID/device

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

I'm looking for a way to create a unique id that can serve as userid, it should survive deinstallations without changing.

why i need it?
with this id i can identify my users, with this id the user have a anonymous account, with his post, likes etc.

I googled a bit and found this.

Now my question is, how can i do that in B4I?

Greetings
 

tufanv

Expert
Licensed User
Longtime User
Hello,

I'm looking for a way to create a unique id that can serve as userid, it should survive deinstallations without changing.

why i need it?
with this id i can identify my users, with this id the user have a anonymous account, with his post, likes etc.

I googled a bit and found this.

Now my question is, how can i do that in B4I?

Greetings
you can use keychain . it will survive the uninstalls.

first check if userid key exists with every launch:
B4X:
p.keychainget("userid")

if it returns empty it means user is first time launching the app. So assign an id to this device
B4X:
p.keychainput("userid",Rnd(1000000,9999999))

At next launches , user id will return the random id generated above even if the user uninstall the app:

B4X:
p.keychainget("userid")

an all in one example can be :

B4X:
dim userid as string
userid = p.KeyChainGet("userid")
  
        If userid="" Then
            userid=Rnd(1000000,9999999)
            p.KeyChainPut("userid",userid)
        Else
        End If
  
    Log("user id : " &userid)
 
Upvote 0
Top