2015-10-16 22 views
0

所以我試圖保存的位置,顯示名稱和圖像文件解析,我成功地在iOS 9更新之前保存圖像,但現在我得到一個錯誤解析文件太大。這只是圖像選擇器中的一個圖像。顯示名稱在我第一次嘗試時保存,但不在第二次,位置根本沒有。謝謝您的幫助!保存信息給用戶在解析iOS 9

func saveUserInfo() { 

    //saves picture data to user 

    let pictureData = UIImagePNGRepresentation(profileImageView.image!) 

    let file = PFFile(name: "image", data: pictureData!) 

    file.saveInBackgroundWithBlock { (success, error) -> Void in 

     if success { 

     self.user.setObject(file, forKey: "profilePicture") 
     self.user.saveInBackground() 

     } 

     else { 
      print("error: \(error?.localizedDescription)") 
     } 
    } 

    //saves geo point to user (location) 

    PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint, error) -> Void in 

     if error == nil { 

      self.user.setObject(geoPoint!, forKey: "location") 
      self.user.saveInBackground() 
     } 

     else { 
      print("error: \(error?.localizedDescription)") 
     } 

    //saves display name 

     let displayName = self.displayName.text 

     self.user.setObject(displayName!, forKey: "displayName") 
     self.user.saveInBackground() 
    } 
} 

方法得到的GeoPoint其中工程

func getParseGeoPoint() { 

    PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint: PFGeoPoint?, error: NSError?) -> Void in 

     if (error == nil) { 

     self.userGeoPoint = geoPoint 
     } 

     else if let error = error { 

      print("error: \(error.localizedDescription)") 
     } 

    } 

} 

編輯:

我嘗試保存一次全部,但應用程序仍然崩潰

func saveUserInfo() { 

    //saves picture data to user 

    let pictureData = UIImagePNGRepresentation(profileImageView.image!) 

    let file = PFFile(name: "image", data: pictureData!) 

    file.saveInBackgroundWithBlock { (success, error) -> Void in 

     if success { 

     self.user.setObject(file, forKey: "profilePicture") 
     self.user.setObject(self.userGeoPoint!, forKey: "location") 
     self.user.setObject(self.displayName.text!, forKey: "displayName") 

     self.user.saveInBackground() 

     } 

     else { 
      print("error: \(error?.localizedDescription)") 
     } 
    } 

回答

0

你爲什麼不一次把所有的數據保存到你的用戶對象?在geoPointForCurrentLocationInBackground成功關閉中將所有數據添加到您的用戶對象,並在一次保存中將其上傳。 另外,要上傳到解析的PFFile的最大大小僅爲10 MB,因此請檢查文件的大小。

+0

好吧,我上面編輯過,它仍然崩潰。 我有它獲取geoPoint當視圖加載,然後將其設置爲全球屬性,我保存時,用戶保存他們的個人資料,應該沒問題吧? 再次感謝! – Echizzle

+0

您不需要先上傳文件。如果將PFFile分配給對象,則在保存該對象時將自動上傳該對象。另一個問題是你爲什麼通過自己訪問你的用戶對象?您可以使用PFUser.currentUser()方法訪問您的用戶對象 –