进入Parse的空文件

时间:2015-05-28 05:35:00

标签: ios xcode parse-platform

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

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

    }
}

}

1 个答案:

答案 0 :(得分:0)

您正在上传图片,具体取决于对象保存的响应,可能是因为它,有时无法获得成功调用图片上传。 独立尝试并让我知道它是否有效,

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

}
}
}