“保存PFInstallation.currentInstallation()时,必须在此操作中指定至少一个ID字段(installationId,deviceToken)”错误

时间:2015-02-10 02:05:03

标签: ios swift parse-platform

目前该应用程序在模拟器iphone 5上首次安装时运行正常,但是当我将模拟器切换到另一台设备即iphone 6时,会出现此错误:

" 2015-02-10 12:58:45.339 booster [31100:838876]错误:必须在此操作中指定至少一个ID字段(installationId,deviceToken)(代码:135,版本:1.4。 1)"

当用户从第一个viewcontroller使用Facebook登录并且currentInstallation与PFUser.currentUser()一起保存时,会发生此错误。用户名

我需要添加什么才能发生此错误?

   @IBAction func loginPressed(sender: AnyObject) {

    displayActivity()
    var permissions = ["public_profile"]


    PFFacebookUtils.logInWithPermissions(permissions, {
        (user: PFUser!, error: NSError!) -> Void in
        if user == nil {
            self.activityIndicator.stopAnimating()
            UIApplication.sharedApplication().endIgnoringInteractionEvents()
            NSLog("Uh oh. The user cancelled the Facebook login.")

        }
        else if user.isNew {

            var FBSession = PFFacebookUtils.session()
            var accessToken = FBSession.accessTokenData.accessToken

            let url = NSURL(string: "https://graph.facebook.com/me/picture?type=large&return_ssl_resources=1&access_token="+accessToken)
            let urlRequest = NSURLRequest(URL: url!)
            NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in
                let image = PFFile(name: "image.png", data: data)
                user["imageFile"] = image
                user["blockCount"] = 0
                user["reportCount"] = 0
                user["blockedBy"] = [""]

                FBRequestConnection.startForMeWithCompletionHandler({
                    connection, result, error in

                    self.activityIndicator.stopAnimating()
                    UIApplication.sharedApplication().endIgnoringInteractionEvents()
                    user["name"] = result["name"]
                    user["timezone"] = result["timezone"]


                    user.saveInBackgroundWithBlock({ (success: Bool, error: NSError!) in
                        if error == nil{
                            println("facebook sign up success!")
                            var installation = PFInstallation.currentInstallation()
                            installation["userID"] = PFUser.currentUser().username
                            installation.saveInBackgroundWithBlock({ (success, error) -> Void in
                                if success == true{
                                    self.performSegueWithIdentifier("loginSegue3", sender: nil)
                                }
                            })
                        }
                        else{
                            self.activityIndicator.stopAnimating()
                            UIApplication.sharedApplication().endIgnoringInteractionEvents()
                            println(error)
                        }
                    })
                })
            }
        }
        else {
            user.saveInBackgroundWithBlock({ (success: Bool, error: NSError!) in
                if error == nil{
                    println("existing facebook user log in success!")
                    var installation = PFInstallation.currentInstallation()
                    installation["userID"] = PFUser.currentUser().username
                    installation.saveInBackgroundWithBlock({ (success, error) -> Void in
                        if success == true{
                            self.performSegueWithIdentifier("loginSegue3", sender: nil)

                        }
                    })

                }
                })

            NSLog("User logged in through Facebook!")
            self.activityIndicator.stopAnimating()
            UIApplication.sharedApplication().endIgnoringInteractionEvents()

        }
    })

}

0 个答案:

没有答案