【问题标题】:PFUser currentUser not saving in iOS7PFUser currentUser 未在 iOS7 中保存
【发布时间】:2015-05-10 08:00:13
【问题描述】:

我正在使用下面的代码来保存当前登录的用户和自定义字段。我允许用户填写信息然后保存。我使用 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。救命!

【问题讨论】:

    标签: ios iphone parse-platform pfuser


    【解决方案1】:

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

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

    【讨论】:

    • 应用程序甚至没有进入第一个 if 语句进行检查。它卡在储蓄上。只是注意到删除该应用程序可以暂时解决问题。这似乎是在注销并与其他用户登录后发生的。即 PFUser currentUser 更改。更新问题
    【解决方案2】:

    我花了很长时间才意识到,尽管我从未真正找到问题本身的解决方案,但我找到了解决方法。我将 currentUser 保存在 currentInstallation 中,将 currentInstallation 保存在 currentUser 中。这导致保存时出现问题。我还通过直接发送频道数组而不是使用 addUniqueObject 来在 currentInstallation 上保存频道。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多