Created
November 19, 2017 15:43
-
-
Save anonymous/1e3075e8bc2b56118a1d9f348f14c2dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)saveImage:(UIImage * _Nonnull)image metadata:(NSDictionary * _Nullable)metadata | |
{ | |
#if 0 // attach only Exif | |
NSDictionary *exif = metadata[@"{Exif}"]; | |
metadata = (exif == nil)? nil : @{ @"{Exif}" : exif }; | |
#endif | |
NSMutableData *jpegData = [[NSMutableData alloc] init]; | |
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)jpegData, kUTTypeJPEG, 0, NULL); | |
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)metadata); | |
BOOL writeSuccess = CGImageDestinationFinalize(imageDestination); | |
CFRelease(imageDestination); | |
if(!writeSuccess) | |
return; | |
[[PHPhotoLibrary sharedPhotoLibrary] | |
performChanges:^{ | |
PHAssetCreationRequest *assetCreation = [PHAssetCreationRequest creationRequestForAsset]; | |
[assetCreation addResourceWithType:PHAssetResourceTypePhoto data:jpegData options:nil]; | |
} | |
completionHandler:^(BOOL success, NSError * _Nullable error) { | |
NSLog(@"%d, %@", success, error); | |
} | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment