2016-12-01 56 views
0

試圖保存登錄解析用戶的值,它只適用於第一次,但是當我關閉應用程序並重新打開它時,它不再工作。無法修改用戶解析

這是我使用的保存代碼似乎好

PFUser.current()["about"] = textfield.text 
PFUser.current().saveInBackground() 

,這是錯誤試圖保存對象,以當前用戶,當我得到。

PFKeychainStore failed to set object for key 'currentUser', with error: -34018 
or 
cannot modify user objectIDxx 

這開始後,我

回答

1

是你使用「撤銷會議」之前安裝瞭解析服務器,而不是parse.com發生了什麼?否則,parse-server需要你使用它們。您可以查看遷移教程here

你需要添加這個初始化後解析:

[PFUser enableRevocableSessionInBackground] 

,然後你將需要重新登錄用戶,如果你從parse得到一個「無效的會話」錯誤。

// Swift 
class ParseErrorHandlingController { 
    class func handleParseError(error: NSError) { 
    if error.domain != PFParseErrorDomain { 
     return 
    } 

    switch (error.code) { 
    case kPFErrorInvalidSessionToken: 
     handleInvalidSessionTokenError() 

    ... // Other Parse API Errors that you want to explicitly handle. 
    } 

    private class func handleInvalidSessionTokenError() { 
    //-------------------------------------- 
    // Option 1: Show a message asking the user to log out and log back in. 
    //-------------------------------------- 
    // If the user needs to finish what they were doing, they have the opportunity to do so. 
    // 
    // let alertView = UIAlertView(
    // title: "Invalid Session", 
    // message: "Session is no longer valid, please log out and log in again.", 
    // delegate: nil, 
    // cancelButtonTitle: "Not Now", 
    // otherButtonTitles: "OK" 
    //) 
    // alertView.show() 

    //-------------------------------------- 
    // Option #2: Show login screen so user can re-authenticate. 
    //-------------------------------------- 
    // You may want this if the logout button is inaccessible in the UI. 
    // 
    // let presentingViewController = UIApplication.sharedApplication().keyWindow?.rootViewController 
    // let logInViewController = PFLogInViewController() 
    // presentingViewController?.presentViewController(logInViewController, animated: true, completion: nil) 
    } 
} 

// In all API requests, call the global error handler, e.g. 
let query = PFQuery(className: "Object") 
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in 
    if error == nil { 
    // Query Succeeded - continue your app logic here. 
    } else { 
    // Query Failed - handle an error. 
    ParseErrorHandlingController.handleParseError(error) 
    } 
} 
+0

是的,我試過這個,仍然發生,刪除我的應用程序,創造了新的帳戶。不知道什麼是錯的。 – TestDjay