繁体   English   中英

PFUser currentUser未保存在iOS7中

[英]PFUser currentUser not saving in iOS7

我正在使用以下代码使用自定义字段保存当前登录的用户。 我允许用户填写信息,然后保存。 我使用GCM在自己的线程中使用了两种保存方法,并使用了saveInBackgrounWithBlock。 在iOS8上,此方法可以正常运行,但在iOS7上,永远不会保存,也不会调用完成块。 有任何想法吗? 谢谢

       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();
                }
            })
        }

更新1:我注意到删除该应用程序可以暂时解决该问题。 但是,注销并与其他用户登录后(即更改当前用户),该问题将再次弹出。

更新2:问题似乎是由PFInstallation引起的。 使用addUniqueObject会导致问题。 调用此方法后,所有保存都将停止运行iOS7。 即使在PFUser上。 PFUser具有安装设置,反之亦然。 他们的数组。

更新3:似乎不仅是addUniqueObject,而且还有PFInstallation.currentInstallation上的任何setObject。 救命!

您还应该检查第一个参数(isSuccess):

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

我花了很长时间才意识到,尽管我从未真正找到解决问题的方法,但还是找到了解决方法。 我将currentUser保存在currentUser中,将currentInstallation保存在currentUser中。 保存时这会引起问题。 我还通过直接发送通道数组而不是使用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