简体   繁体   English

上传图片进行解析

[英]Upload image to parse

I am new to iOS, I want to upload image to parse. 我是iOS新手,我想上传图片进行解析。 Here is the code 这是代码

func imagePickerController(picker : UIImagePickerController, didFinishPickingMediaWithInfo info : [NSObject : AnyObject]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        let scaledImage = self.scale(pickedImage, and : CGSizeMake(100, 100))
        let imagedata = UIImagePNGRepresentation(scaledImage)
        let imageFile = PFFile(data : imagedata)
        PFUser.currentUser()?.setObject(imageFile, forKey : "profileImage")
        PFUser.currentUser()!.saveInBackgroundWithBlock {
            (success : Bool, error : NSError?) -> Void in
            if (success) {
                println("success")//Neither success nor fail is printing
            } else {
                println("fail")
            }
        }

      //  print("")
        dismissViewControllerAnimated(true, completion : nil)
        let viewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("yoyo") as? UIViewController
        self.presentViewController(viewcontroller!, animated : true, completion : nil)

    }
}

The problem is databrowser is not populated with image. 问题是数据浏览器未填充图像。 Thanks. 谢谢。

You may want to use the saveInBackgroundWithBlock like this 您可能要像这样使用saveInBackgroundWithBlock

var parseImageFile = PFFile(name: "uploaded_image.png", data: imageData)
                    posts["imageFile"] = parseImageFile
                    posts.saveInBackgroundWithBlock({
                        (success: Bool, error: NSError?) -> Void in

                        if error == nil {
                            //back to home
                            println("Success")
                            self.performSegueWithIdentifier("something", sender: self)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM