iOS with Parse. Pfuser.Currentuser() Not Getting Cached. Returns Nil After App Restart

Parse PFUser.currentUser returns nil - Swift

I discovered that this problem appeared because the segue signInToNavigation was wired from the Login-button, instead from the login view controller itself. This resulted in the segue being executed before the login function was executed, and therefore the PFUser.currentUser()object was not yet assigned when the table view loaded. I solved this by rewiring the segues. Stupid slip-up on my side.

Thanks to Ryan Kreager and Wain for taking time to help me figure out this issue!

iOS App Extension has PFUser currentUser set to nil

Found the problem:

I wasn't enabling local datastore in the app extension. Data store must be enabled both in the app itself and the app extension. Adding [Parse enableLocalDatastore]; before initializing Parse and after data sharing code (enableDataSharingWithApplicationGroupIdentifier:containingApplication:) solved my problem.

To keep the current user logged in using swift and parse

That snippet of code should work as long as the session in parse is still up.

I ran into the same problem because I wrote that code inside of func viewDidLoad().

When i wrote:

func viewDidAppear(animated:Bool){
super.viewDidAppear(animated)
var currentUser = PFUser.currentUser()
if currentUser != nil {
// Do stuff with the user
} else {
// Show the signup or login screen
}

it worked perfectly fine

How to cache PFUser locally if it fails to sign up due to internet failure?

I ended up using PFUser.enableautomaticuser() and then make changes to PFUser.currentUser().

At last I will attempt to signUp, if failed, I will call saveEventually() so that next user logs in. They will retain the previous PFUser reference, so that their information won't be lost in case the user starts the application without internet.



Related Topics



Leave a reply



Submit