gpt4 book ai didi

ios - 进入 Parse 的空文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:36:11 25 4
gpt4 key购买 nike

我已经让用户可以选择他们的照片并发布它。我的问题是,当互联网速度很慢时,上传到解析云需要时间,但有时由于我的应用程序崩溃,空文件而不是图像被添加到解析中。怎么了?

@IBOutlet var profileimage: UIImageView!
@IBOutlet var addimageText: UIButton!
@IBOutlet var imageMessage: UITextField!



@IBAction func addimage(sender: AnyObject) {
var imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.delegate = self
self.presentViewController(imagePicker, animated: true, completion: nil)


}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
profileimage.image = image
self.dismissViewControllerAnimated(true, completion: nil)

addimageText.titleLabel?.text = "Change"
}

func SwipeDown(){
var swipe: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "dismissKeyboard")

swipe.direction = UISwipeGestureRecognizerDirection.Down

self.view.addGestureRecognizer(swipe)

}

override func viewDidLoad() {
super.viewDidLoad()
SwipeDown()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}



func textFieldShouldReturn(textField: UITextField) -> Bool {

textField.resignFirstResponder()

return true;
}

func dismissKeyboard(){
self.imageMessage.resignFirstResponder()
}



@IBAction func uploadbutton(sender: AnyObject) {
var imageText = imageMessage.text



if profileimage.image == nil{
println("image not uploaded")
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Fail!"
alertview.message = "Please Select The Image";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()


} else {
var images1 = PFObject(className: "images")
images1["imageText"] = imageText
images1["uploader"] = PFUser.currentUser()
images1.saveInBackgroundWithBlock{
(success: Bool,error: NSError?)-> Void in

if error == nil {
var imageData = UIImagePNGRepresentation(self.profileimage.image)
var parseimagefile = PFFile(data: imageData)
images1["imageFile"] = parseimagefile
images1.saveInBackgroundWithBlock{
(success: Bool, error:NSError?)-> Void in

if error == nil{
println("image uploaded")
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Uploaded "
alertview.message = "Photo Uploaded Successfully";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()
self.performSegueWithIdentifier("imagetohome", sender: self)


}else {
println(error)
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Failed!"
alertview.message = "Photo Uploaded Unsuccessfully";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()

}

}

}else {
println(error)
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Failed!"
alertview.message = "Connection Failure";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()
}
}

}
}

最佳答案

您正在根据对象保存的响应上传图片,可能正因为如此,有时它不会成​​功调用图片上传。独立尝试,让我知道它是否有效,

@IBAction func uploadbutton(sender: AnyObject) {
var imageText = imageMessage.text



if profileimage.image == nil{
println("image not uploaded")
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Fail!"
alertview.message = "Please Select The Image";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()


} else {
var images1 = PFObject(className: "images")
var imageData = UIImagePNGRepresentation(self.profileimage.image)
var parseimagefile = PFFile(data: imageData)
images1["imageFile"] = parseimagefile
images1.saveInBackgroundWithBlock{
(success: Bool, error:NSError?)-> Void in

if error == nil{
println("image uploaded")
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Uploaded "
alertview.message = "Photo Uploaded Successfully";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()
self.performSegueWithIdentifier("imagetohome", sender: self)


}else {
println(error)
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Failed!"
alertview.message = "Photo Uploaded Unsuccessfully";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()

}

}
images1["imageText"] = imageText
images1["uploader"] = PFUser.currentUser()
images1.saveInBackgroundWithBlock{
(success: Bool,error: NSError?)-> Void in

if error == nil {


}else {
println(error)
var alertview:UIAlertView = UIAlertView()
alertview.title = "Photo Upload Failed!"
alertview.message = "Connection Failure";
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.show()
}
}

}
}
}

关于ios - 进入 Parse 的空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30497986/

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