Thanks for reading. I\'ve created a GIF using methods from this question:
Create and and export an animated gif via iOS?
I\'m trying to use the only method that
Here is an updated answer using PHPhotoLibrary, since ALAssetsLibrary is deprecated.
I used this answer from another user - 陈星旺
PHPhotoLibrary save a gif data
NSString *exportPath = [NSTemporaryDirectory() stringByAppendingString:@"/animated.gif"];
NSURL *fileURL = [NSURL fileURLWithPath:exportPath isDirectory:NO];
NSData * gifData = [NSData dataWithContentsOfFile:fileURL.absoluteString];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
[[PHAssetCreationRequest creationRequestForAsset]
addResourceWithType:PHAssetResourceTypePhoto
data:gifData
options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"image saved!");
} else {
NSLog(@"error saving image - %@", error ? error.localizedDescription : @"");
}
}];
If you needed to download the GIF data from a URL, you could use this:
NSData *gifData = [NSData dataWithContentsOfURL:theGIFsURL];