gpt4 book ai didi

ios - 应用重启时照片丢失并取消固定

转载 作者:行者123 更新时间:2023-11-28 08:59:45 25 4
gpt4 key购买 nike

我正在使用 Parse pinInBackground 功能来保存稍后将与 parse 同步的信息,但该信息的一部分是已拍摄的照片,但是当我在信息之前重新启动应用程序时已与 Parse 同步,图像丢失。如何在重新启动应用程序时不丢失图片。我必须在本地保存吗?如果是这样,在哪里以及如何?提前谢谢您,如果需要我的任何代码,请告诉我。

//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)")
}
})
}

最佳答案

Parse 将照片保存在 tmp/ 目录中,当应用程序重新启动时,tmp/ 被删除。将图片保存到 Documents/ 目录,同步时,从 Documents/ 中拉取图片,然后保存。我不知道代码,所以如果有人能给出解释,那将是 greeeeaaat

关于ios - 应用重启时照片丢失并取消固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32221163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com