Bad*_*der 3 objective-c nsdata phphotolibrary ios9
我在新的PHPhotoLibrary中找不到与ALAssetsLibrary-> writeImageDataToSavedPhotosAlbum类似的方法,因为在iOS 9中不推荐使用ALAssetsLibrary我无法保存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);
}
}];
Run Code Online (Sandbox Code Playgroud)
小智 8
我曾经NSData保存过gif图像,在iOS8之后弃用了ALAssetsLibrary方法UIImageWriteToSavedPhotosAlbum,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);
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2466 次 |
| 最近记录: |