在新的ALAssetsLibrary->writeImageDataToSavedPhotosAlbum中找不到与PHPhotoLibrary类似的方法,因为ALAssetsLibrary在iOS 9中不推荐使用,所以我无法保存GIF,可能我正在使用以下代码
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageWithData:gifdata]];
placeholder = [assetRequest placeholderForCreatedAsset];
photosAsset = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection
assets:photosAsset];
[albumChangeRequest addAssets:@[placeholder]];
} completionHandler:^(BOOL success, NSError *error) {
if (success)
{
}
else
{
NSLog(@"%@", error);
}
}];发布于 2016-02-13 02:16:09
我通过创建临时文件并使用:
creationRequestForAssetFromImageAtFileURL
发布于 2016-11-02 06:31:31
我使用NSData保存gif映像,ALAssetsLibrary方法UIImageWriteToSavedPhotosAlbum在iOS8之后不再推荐,api说我们可以使用PHAssetCreationRequest方法[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];保存这个gif映像数据,所以您也可以使用url请求来保存gifs。
守则如下:
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"];
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);
}];发布于 2018-08-09 08:42:52
我已经通过使用Photos框架成功地将gif文件保存到Photos图片库
PHPhotoLibrary.shared().performChanges ({
let url = URL(fileURLWithPath: "your file path")
PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: url)
}) { saved, error in
if saved {
print("Your image was successfully saved")
}
}希望能帮上忙!
https://stackoverflow.com/questions/35374919
复制相似问题