Reputation: 51
I've tried using UIImageWriteToSavedPhotosAlbum and ALAssetsLibrary to save my gif to the photo album. But when I try to email the gif it does not animate. I'm pretty sure the meta data is being lost when it gets saved. Does anyone know how I can preserve the gif meta data?
Thanks
Upvotes: 4
Views: 4581
Reputation: 3580
GIF can be easily saved from URL to Album
let url = FileManager.default.urlForFile("lion.gif") // Document Directory or Bundle url path
PHPhotoLibrary.shared().performChanges ({
PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: url)
}) { saved, error in
if saved {
print("Your image was successfully saved")
}
}
Upvotes: 0
Reputation: 2581
Quite an old question, but it might help someone!
I use this code to save GIF in photo album and it works fine, tested by opening GIF in MailViewComposer and iMessage.
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSData *data = [NSData dataWithContentsOfFile:tempPath]; // Your GIF file path which you might have saved in NSDocumentDir or NSTempDir
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"Error Saving GIF to Photo Album: %@", error);
} else {
// TODO: success handling
NSLog(@"GIF Saved to %@", assetURL);
success(tempPath);
}
}];
Upvotes: 5