gpt4 book ai didi

ios - 如何将从相机拍摄的图像保存到 Parse?

转载 作者:行者123 更新时间:2023-11-30 14:08:38 25 4
gpt4 key购买 nike

出于某种奇怪的原因,我无法将 iPhone 相机拍摄的图像保存到 Parse 中。不过,我可以成功保存从网络上保存的图像、短信,甚至屏幕截图。

每当我尝试从相机保存图像时,它都会在解析中留下未定义的列。可能是什么问题?

这是我的 PFObject 代码:

var posts = PFObject(className: "Product")
posts["shortDescription"] = productShortDescription
posts["user"] = PFUser.currentUser()
posts["longDescription"] = productLongDescription
posts["title"] = productTitle
posts["price"] = productPrice
posts.saveInBackgroundWithBlock({
(success: Bool, error: NSError?) -> Void in

if error == nil {
//success saving, now save image

//create image data

var imageData = UIImagePNGRepresentation(self.newItemImageView.image)


//create parse file

var parseImageFile = PFFile(name: "upload_image.png", data: imageData)
posts["imagePNG"] = parseImageFile
//parseImageFile.saveInBackground()
parseImageFile.saveInBackgroundWithBlock({
(success: Bool, error: NSError?) -> Void in
if error == nil {

posts.saveInBackground()
// take user home

println("data uploaded")
self.performSegueWithIdentifier("returnHomeAfterUpload", sender: self)
}else {
println(error)

}

这是我的 UIImagePickerController 代码:

@IBAction func addNewItemImageView(sender: AnyObject) {

var imagePicker: UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
newItemImageView.image = image

self.dismissViewControllerAnimated(true, completion: nil)

newItemImageUploadText.titleLabel?.text = "New"

}

谢谢!

最佳答案

看看这个:https://github.com/joshliu/treehouse-ios/tree/master/ribbit它是一个允许您拍摄视频和图片并将其发送给其他用户的程序。我已经使用过它,但是是 Android 版本,很抱歉我无法给您确切的代码,但我确信它正是您正在寻找的。

关于ios - 如何将从相机拍摄的图像保存到 Parse?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32030106/

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