简体   繁体   English

PFUser currentUser未保存在iOS7中

[英]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. 我使用GCM在自己的线程中使用了两种保存方法,并使用了saveInBackgrounWithBlock。 On iOS8, this works ok but on iOS7 saving never happens and the completion block is never called. 在iOS8上,此方法可以正常运行,但在iOS7上,永远不会保存,也不会调用完成块。 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. 更新1:我注意到删除该应用程序可以暂时解决该问题。 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. 更新2:问题似乎是由PFInstallation引起的。 Using addUniqueObject causes issues. 使用addUniqueObject会导致问题。 After calling this method, any saves stops working iOS7. 调用此方法后,所有保存都将停止运行iOS7。 Even on the PFUser. 即使在PFUser上。 The PFUser has the installation setup and vice versa. PFUser具有安装设置,反之亦然。 An array of them. 他们的数组。

Update 3: Seems like it's not just the addUniqueObject, but any setObject on the PFInstallation.currentInstallation. 更新3:似乎不仅是addUniqueObject,而且还有PFInstallation.currentInstallation上的任何setObject。 Help! 救命!

you should check your first param (isSuccess) as well: 您还应该检查第一个参数(isSuccess):

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. 我将currentUser保存在currentUser中,将currentInstallation保存在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. 我还通过直接发送通道数组而不是使用addUniqueObject来将通道保存在currentInstallation中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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