0

I log in as a guest user. I force quit the app (quickly press home button, swipe up on app - just to clarify). I re-start the app. The anonymous user is still logged in. I thought it would be as simple as this in my AppDelegate:

    func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    PFUser.logOut()
}

Clearly, it is not. Do I need to set the PFUser.currentUser to nil in the applicationWillTerminate ? Or is there a better way to handle this scenario?

lostinthebits
  • 661
  • 2
  • 11
  • 24

1 Answers1

1

Your app isn't informed if the user force quits your app. There's no way to do want you want (reliably).

As an alternative, you could log users out when the app launches.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • So when a user force quits an app, 8.0 will pretty much always return them to the previous state. Is it sort of like a race condition where the function call to logout is not quick enough? So when the user launches and app, you're saying just do a check to see if someone is logged in and log them out? – lostinthebits Feb 24 '15 at 03:22
  • 1
    iOS doesn't guarantee `applicationWillTerminate(_:)` is called when you force quit the app, and even if it did, your app would terminate before the background process used by `PFUser.logOut()` completes. So, yes, I'm saying you can call `PFUser.logOut()` at app launch to approximate what you want. – Aaron Brager Feb 24 '15 at 03:27