Archivos vacíos que ingresan en Parse

He realizado donde el usuario puede seleccionar su foto y publicarla. Mi problema es que cuando Internet es lento, se necesita time para upload a la nube de Parse, pero a veces, en lugar de files vacíos de image, se agregan al parse debido a que mi aplicación se bloquea. ¿Qué sucede?

@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() } } } } 

}

Usted está cargando la image dependiendo de la respuesta del object guardado, puede ser debido a ella, algunas veces no tendrá éxito llamar a la carga de la image. Pruébelo de forma independiente y déjeme saber si funciona,

 @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() } } } } }