Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从UIImagePickerControllerDelegate获取NSURL到_Ios_Swift - Fatal编程技术网

Ios 如何从UIImagePickerControllerDelegate获取NSURL到

Ios 如何从UIImagePickerControllerDelegate获取NSURL到,ios,swift,Ios,Swift,我正在使用CloudKit保存用户创建的记录。在保存字符串、整数和CLLocation之后,接下来我要将图像保存到记录中 在使用imagePickerController函数的UIImagePickerController Delegate中,我可以获得对象的NSURL信息,因此我想我可以从中获得NSURL: func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info

我正在使用CloudKit保存用户创建的记录。在保存字符串、整数和CLLocation之后,接下来我要将图像保存到记录中

在使用imagePickerController函数的UIImagePickerController Delegate中,我可以获得对象的NSURL信息,因此我想我可以从中获得NSURL:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
           imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage

    let mediaURL = info[UIImagePickerControllerReferenceURL]!
    captured_mediaUrl = mediaURL as! NSURL
    print(mediaURL)
    var edittedImage: UIImage = ((info[UIImagePickerControllerOriginalImage] as? UIImage)!)

    imageView.image = edittedImage
     imageView.contentMode = .ScaleAspectFit

    self.dismissViewControllerAnimated(true, completion: nil)

}
然后我想我使用捕获的_MediaUrl将CKRecords保存为CKAsset:

@IBAction func save(sender: AnyObject) {

    var createdCoffee = Coffee()
    createdCoffee.name = self.coffeeName.text!
    createdCoffee.cafe = self.cafeName.text!
    createdCoffee.rating = Double(ratingController.rating)
    createdCoffee.place = savedLocation
    self.coffee = createdCoffee
    self.delegate?.viewController(self, didAddCoffee: self.coffee)


    //create the cloudkit record here
    let container = CKContainer.defaultContainer()
    let publicData = container.publicCloudDatabase


    let record = CKRecord(recordType: "Coffee")
    record.setValue(coffee!.name, forKey: "Name")
    record.setValue(coffee!.cafe, forKey: "Cafe")
    record.setValue(coffee!.rating, forKey: "Rating")
    record.setValue(coffee!.place, forKey: "Place")
    record.setValue(CKAsset(fileURL: captured_mediaUrl!), forKey: "Image")
    publicData.saveRecord(record, completionHandler: { record, error in
        if error != nil {
            print(error)
        }

    })
但是,这将返回一个错误:

资产-library://asset/asset.JPG?id=76A0FFD5-84A2-4B68-BA2A-CEEC0F2C8B6C&ext=JPG
2016-04-11 12:55:37.918咖啡应用程序[1112:199929]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因是:“非文件URL”


在CKRecords中保存图像的正确方法是什么?

您是否从这里获得输出
捕获的\u mediaUrl
是的,捕获的\u mediaUrl实际上是“资产”-library://asset/asset.JPG?id=76A0FFD5-84A2-4B68-BA2A-CEEC0F2C8B6C&ext=JPG“一旦获得文件路径或未记录,请检查此处。setValue(CKAsset(fileURL:captured_mediaUrl!),forKey:“Image”)您是否从这里获得输出
捕获的\u mediaUrl
是的,捕获的\u mediaUrl实际上是“资产”-library://asset/asset.JPG?id=76A0FFD5-84A2-4B68-BA2A-CEEC0F2C8B6C&ext=JPG“一旦获得文件路径或未记录,请检查此处。setValue(CKAsset(fileURL:captured_mediaUrl!),forKey:“Image”)