Photo frame: saving exif data from the collector (aperture, focal length, shutter speed, ...)

I am trying to make the equivalent of writeImageToSavedPhotosAlbum using the new Photo frame.

To save the image, I only do this:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { let image = info[UIImagePickerControllerOriginalImage] as UIImage PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in let changeRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image) }, completionHandler: { (success, error) -> Void in // }) } 

Of course, there is no magic, and since I am not doing anything from

 info[UIImagePickerControllerMediaMetadata] 

the above code does not save the metadata in the “Camera Roll”, as you can see using the Preview.app screenshot when I connect the iPhone to my Mac.

enter image description here

You get this view by opening Preview.app, choosing File> Import from the “name of your device”; then you can browse your photos and see that those that were taken using the Exif application for the camera display exif), for example, the focal length, and those that were saved with the code above show empty values .. p>

Now the documentation for creating aRequestForAssetFromImage says:

To set the metadata properties of a newly created asset, use the corresponding properties of the change request (listed in the "Change" Assets section).

What are the links to "+ changeRequestForAsset:" and 4 properties (createDate, location, favorite, hidden) that glow a bit. What about other properties you want to keep (e.g. aperture, focal length, shutter speed, ...)?

How should you save your metadata from an image using the Photo frame?

+6
source share
1 answer

Here is what I ended up doing:

 extension UIImage { /** Gets the metadata from the photo album :param: info The picker dictionary :param: completionHandler A block to call when the metadata is available */ class func requestMetadata(info: [NSObject : AnyObject], completionHandler: ([NSObject : AnyObject]) -> Void) { let assetUrl = info[UIImagePickerControllerReferenceURL] as! NSURL let result = PHAsset.fetchAssetsWithALAssetURLs([assetUrl], options: nil) if let asset = result.firstObject as? PHAsset { let editOptions = PHContentEditingInputRequestOptions() editOptions.networkAccessAllowed = true asset.requestContentEditingInputWithOptions(editOptions, completionHandler: { (contentEditingInput, _) -> Void in let url = contentEditingInput.fullSizeImageURL let orientation = contentEditingInput.fullSizeImageOrientation var inputImage = CoreImage.CIImage(contentsOfURL: url) completionHandler(inputImage.properties()) }) } else { completionHandler([:]) } } } 
+3
source

Source: https://habr.com/ru/post/982864/