将视频添加到自定义照片集合返回错误
Posted
技术标签:
【中文标题】将视频添加到自定义照片集合返回错误【英文标题】:Adding video to custom Photos collection returning error 【发布时间】:2016-03-20 23:54:17 【问题描述】:我正在使用以下代码将视频导出到自定义照片集:
phphotoLibrary *photoLibrary = [PHPhotoLibrary sharedPhotoLibrary];
__block PHAssetCollection *album;
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
for( int i = 0; i < fetchResult.count; i++)
PHAssetCollection *collection = [fetchResult objectAtIndex:i];
if([collection.localizedTitle isEqualToString:@"Pose Pro"])
album = collection;
break;
if( !album )
__block PHObjectPlaceholder *placeHolder;
[photoLibrary performChanges:^
PHAssetCollectionChangeRequest *changeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"Pose Pro"];
placeHolder = changeRequest.placeholderForCreatedAssetCollection;
completionHandler:^(BOOL success, NSError * _Nullable error)
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[placeHolder.localIdentifier] options:nil];
album = fetchResult.firstObject;
];
[photoLibrary performChanges:^
PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:_videoURL];
PHObjectPlaceholder *assetChangePlaceHolder = assetChangeRequest.placeholderForCreatedAsset;
PHFetchResult *videoAssets = [PHAsset fetchAssetsInAssetCollection:album options:nil];
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:album assets:videoAssets];
[albumChangeRequest addAssets:@[assetChangePlaceHolder]];
completionHandler:^(BOOL success, NSError * _Nullable error)
NSLog(@"Error: %@", [error localizedDescription]);
];
当此代码运行时,我收到以下错误消息:
Error Domain=NSCocoaErrorDomain Code=-1 "(null)"
此代码看起来与其他代码示例非常相似。有谁知道我做错了什么?
【问题讨论】:
【参考方案1】:我想通了。视频 URL 引用的是视频的包含文件夹,而不是实际的视频本身。
【讨论】:
以上是关于将视频添加到自定义照片集合返回错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 PHPhotoLibrary 将照片添加到自定义文件夹还会将照片添加到相机胶卷