简体   繁体   中英

PFUser currentUser not saving in iOS7

I am using the below code to save the currently logged in user with custom field. I allow the user to fill in information and then save. I used both the save methods on my own threading using GCM and used the saveInBackgrounWithBlock. On iOS8, this works ok but on iOS7 saving never happens and the completion block is never called. Any ideas? Thanks

       if PFUser.currentUser() != nil {
            PFUser.currentUser().setObject(installation, forKey: "installation")
            PFUser.currentUser().saveInBackgroundWithBlock({ (bool: Bool, error: NSError?) -> Void in
                if(error != nil) {
                    let alert = UIAlertView(title: "Problem Saving", message: "Make sure you are connecte to the internet and try again", delegate: nil, cancelButtonTitle: "OK")
                    alert.show();
                }
            })
        }

Update 1: I noticed that deleting the app resolves the issue temporarily. However, after signing out and signing in with other user (ie changing the current user), the issue will pop up again.

Update 2: The issue seems to be coming from PFInstallation somehow. Using addUniqueObject causes issues. After calling this method, any saves stops working iOS7. Even on the PFUser. The PFUser has the installation setup and vice versa. An array of them.

Update 3: Seems like it's not just the addUniqueObject, but any setObject on the PFInstallation.currentInstallation. Help!

you should check your first param (isSuccess) as well:

if (bool == YES && error != nil) -> success
else -> failure

It took me a long while to realise, and even though I never actually found a solution to the problem itself, I found a workaround. I was saving the currentUser in the currentInstallation and the currentInstallation in the currentUser. This was causing issues when saving. I also saved channels on the currentInstallation by sending an array of channels directly instead of using addUniqueObject.

    let installation = PFInstallation.currentInstallation()
    installation.channels = channels;
    installation.saveInBackground()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM