将 AppData 中的 gif 动画保存到相册 - iOS 11
Saving an animated gif from AppData to photo album - iOS 11
如何将 gif 从 Documents 或 AppData 文件夹(或其他已知路径)保存到 iOS 11 的相册?
已知路径示例:/var/mobile/Containers/Data/Application/[app uuid]/Documents/filename.gif
Older versions of this question keep referencing deprecated ALA*。你如何为 iOS 11 做到这一点?
添加框架基础和照片
#import <Foundation/Foundation.h>
#import <Photos/Photos.h>
int saveGifToGallery(const char *path0){
NSString *path = [NSString stringWithUTF8String:path0];
NSData *data = [NSData dataWithContentsOfFile:path];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@":%d",success);
}];
return 1;
}
如何将 gif 从 Documents 或 AppData 文件夹(或其他已知路径)保存到 iOS 11 的相册?
已知路径示例:/var/mobile/Containers/Data/Application/[app uuid]/Documents/filename.gif
Older versions of this question keep referencing deprecated ALA*。你如何为 iOS 11 做到这一点?
添加框架基础和照片
#import <Foundation/Foundation.h> #import <Photos/Photos.h> int saveGifToGallery(const char *path0){ NSString *path = [NSString stringWithUTF8String:path0]; NSData *data = [NSData dataWithContentsOfFile:path]; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init]; [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options]; } completionHandler:^(BOOL success, NSError * _Nullable error) { NSLog(@":%d",success); }]; return 1; }