将视频添加到自定义照片集合返回错误

时间:2016-03-20 23:54:18

标签: ios photolibrary

我使用以下代码将视频导出到自定义照片集:

 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 个答案:

答案 0 :(得分:0)

我明白了。视频网址引用了视频的包含文件夹,而不是实际的视频本身。