Creating Guest Users

I’ve seen a few people online asking about creating “Guest Users” in Backendless. There has been some discussion in the comments of the docs section but I thought I would share what worked for me. I added the following code to “func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool” in the AppDelegate.swift file.

The UUID will change each time the app launches. For this reason I set it when the app first launches. If the app is deleted from the device, the UUID will be recreated and the user data will be lost.

// Testing to see if the user has previously logged in. If they haven't, store a UUID value in NSUserDefaults incase they use the app as a guest. If they do use it as a guest, I will write their data to a custom "GuestTable" at Backendless using their UUID. If they decide to register, I will pull the data from Backendless and store it in their account under the user table. 

if !NSUserDefaults.standardUserDefaults().boolForKey("hasLaunchedOnce")
    // Create the Bool to show the app has launched at least once.
    NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasLaunchedOnce")

    // Get a UUID and store it in NSUserDefaults for future use if the app is used in guest mode.
    let UUID = NSUUID().UUIDString
    NSUserDefaults.standardUserDefaults().setValue(UUID, forKey: "guestID")

    // Synchronize NSUserDefaults to ensure the changes are saved.

Jon, thank you for sharing it with us and the community! I am sure people will find it helpful.

please how do we relate the above code to java for android. An example will really help me.

If you want to follow the approach described by Jon, you could use the shared preferences API on Android.