gpt4 book ai didi

objective-c - PHPhotoLibrary 保存一个 gif 数据

转载 作者:搜寻专家 更新时间:2023-10-30 19:53:12 31 4
gpt4 key购买 nike

我无法在新的 PHPhotoLibrary 中找到与 ALAssetsLibrary->writeImageDataToSavedPhotosAlbum 类似的方法,因为 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);
}
}];

最佳答案

我使用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);
}];

关于objective-c - PHPhotoLibrary 保存一个 gif 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35374919/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com