我正在使用Parse pinInBackground
功能来保存稍后将与解析同步的信息,但该信息的一部分是已拍摄的照片,但是当我在信息同步之前重新启动应用时解析,图像丢失。
应用程序重新启动后,如何不丢失图片。
我必须在本地保存吗?如果是这样,在哪里以及如何?
提前感谢您,如果需要我的任何代码,请告诉我。
//Here I pin the picture in the background
@IBAction func cameraButton(sender: AnyObject) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated:true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
let pickedImage:UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
let imageData = UIImageJPEGRepresentation(pickedImage, 0.5)
let imageFile:PFFile = PFFile(data: imageData)
locationLogs["photo"] = imageFile
locationLogs.pinInBackgroundWithBlock{ (success: Bool, error: NSError?) -> Void in
if (success) {
self.locationManager.stopUpdatingLocation()
}else{
println("error= \(error)")
}
}
imagePicker.dismissViewControllerAnimated(true, completion: nil)
}
//Query it
func queryAll() {
let query = PFQuery(className:"LocationLogs")
query.fromLocalDatastore()
query.findObjectsInBackgroundWithBlock( { (NSArray results, NSError error) in
if error == nil && results != nil {
println("array = \(results)" )
self.tableData = results!
self.loggedItemsTableView.reloadData()
}else{
println("An error has occured= \(error)")
}
})
}
//Save and unpin it
@IBAction func syncAllButton(sender: AnyObject) {
PFObject.saveAllInBackground(self.tableData as [AnyObject], block: { (success: Bool, error: NSError?) -> Void in
if (success) {
PFObject.unpinAllInBackground(self.tableData as [AnyObject])
println("Pinned Data has successfully been saved")
}else{
println("error= \(error?.localizedDescription)")
}
})
}