objective-c – PHPhotoLibrary保存gif数据
发布时间:2020-12-16 10:12:30 所属栏目:百科 来源:网络整理
导读:我在新的 PHPhotoLibrary中找不到与ALAssetsLibrary- writeImageDataToSavedPhotosAlbum类似的方法,因为在iOS 9中不推荐使用ALAssetsLibrary我无法保存GIF可能我正在使用此代码 [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetChangeReques
我在新的
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); } }]; 解决方法
我使用NSData来保存gif图像,在iOS8之后不推荐使用ALAssetsLibrary方法UIImageWriteToSavedPhotosAlbum,api说我们可以使用
PHAssetCreationRequestmethod [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];保存这个gif图像数据,所以你也可以使用url请求来保存gif 代码如下: 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); }]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |