iOS with Parse. PFUser.currentuser() not getting cached. Returns nil after app restart
Asked Answered
D

2

10

I am building an app with Parse in swift. PFUser.currentuser() always returns nil after the app is stopped and run again. I am using the iOS simulator and the local datastore is enabled. I am using something like this -

if PFUser.currentuser() == nil {
// Perform segue to login screen
}

And for login I am using

PFUser.loginWithUsernameInBackground(...)

The currentuser remains till the app is restarted, after which it is reset to nil. I have even tried to pin the currentuser but it doesn't work. How can I check if the currentuser is being cached locally. Any help would be appreciated. Thanks.

Downhaul answered 29/6, 2015 at 17:26 Comment(3)
Have you found a solution?Mahaliamahan
Got the same issue here.Modality
Try making the call with a block return. Are you getting back the expected user and a nil error back? Also make sure this call is done after calling setApplicationIdBunyan
L
2

For me, the reason is simply the following part is not executed. Be careful of multi-thread. Usually that's the cause.

Parse.setApplicationId("xx","xx")
Lorikeet answered 8/12, 2015 at 8:20 Comment(0)
J
1

Are you sure you're not resetting the simulator and are running on the same one? It should not clear the currentUser. Is it possible you are calling

PFUser.logout()

in 'applicationWillTerminate' in AppDelegate or anywhere else?

Junkie answered 29/6, 2015 at 18:40 Comment(1)
No not using PFUser.logout(). But I am using core data. So my 'appWillTerminate' does include a self.saveContext() call.Downhaul

© 2022 - 2024 — McMap. All rights reserved.