Parse platform 在解析iOS 9中将信息保存给用户
所以我试图保存位置、显示名称和要解析的图像文件,在iOS 9更新之前我成功地保存了图像,但现在我得到一个错误,解析文件太大。这只是图像选择器中的一个图像。我第一次尝试时保存了显示名称,但第二次没有保存,而且位置根本没有保存。谢谢你的帮助Parse platform 在解析iOS 9中将信息保存给用户,parse-platform,ios9,Parse Platform,Ios9,所以我试图保存位置、显示名称和要解析的图像文件,在iOS 9更新之前我成功地保存了图像,但现在我得到一个错误,解析文件太大。这只是图像选择器中的一个图像。我第一次尝试时保存了显示名称,但第二次没有保存,而且位置根本没有保存。谢谢你的帮助 func saveUserInfo() { //saves picture data to user let pictureData = UIImagePNGRepresentation(profileImageView.image!)
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()
}
}
获取有效的地质点的方法
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)")
}
}
为什么不一次性将所有数据保存到用户对象中??将所有数据添加到geoPointForCurrentLocationInBackground成功关闭中的用户对象,并在一次保存中上载它们。
另外,要上传到解析的PFFile的最大大小只有10 MB,所以请检查文件的大小。好的,我在上面编辑过,但仍然会崩溃。我让它在视图加载时获取地质点,然后将其设置为全局属性,当用户保存其纵断面时,我会保存该属性,这应该没问题,对吧?再次感谢!你不需要先上传你的文件。如果您为对象指定了一个PFFile,则在保存该对象时会自动上载该PFFile。另一个问题是为什么要通过self访问用户对象??使用PFUser.currentUser()方法可以在任何地方访问用户对象