0

I'm using the following code to export a video to a custom Photos collection:

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

When this code runs I get the following error message:

Error Domain=NSCocoaErrorDomain Code=-1 "(null)"

This code looks very similar to other code samples. Does anyone have any idea what I could be doing wrong?

PineApps
  • 43
  • 7

1 Answers1

0

I figured it out. The video URL was referencing the video's containing folder and not the actual video itself.

PineApps
  • 43
  • 7