如何访问保存在相机胶卷中的照片的Url

时间:2016-06-08 08:58:38

标签: ios swift

我想保存从相机拍摄的照片的网址或者在相机胶卷中取出并已被选中。

1 个答案:

答案 0 :(得分:0)

你的问题非常模糊,我们无需合作。但无论如何,我刚创建了一个需要逻辑的应用程序,所以我只想和你分享

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    // Clear data if picture is repicked

    imageLocalURL = nil
    imageData = nil

    imageSelected = info[UIImagePickerControllerOriginalImage] as? UIImage

    if info[UIImagePickerControllerReferenceURL] != nil {

        // This would mean that image is chosen from photo library

        referenceURL = info[UIImagePickerControllerReferenceURL] as? NSURL
        let assets = PHAsset.fetchAssetsWithALAssetURLs([referenceURL! as NSURL], options: nil)
        let asset = assets.firstObject
        asset?.requestContentEditingInputWithOptions(nil, completionHandler: { (contentEditingInput, info) in
                    // This would be the URL of your image in photo library
                    self.imageLocalURL = contentEditingInput?.fullSizeImageURL

    } else {

        // This means that image is taken from camera

        imageData = UIImageJPEGRepresentation(imageSelected!, 1.0)

    }

    dismissViewControllerAnimated(true, completion: nil)
}