piemonte/PBJVideoPlayer

save to camera roll

e10jon opened this issue · 1 comments

i'm giving myself a headache trying to figure out AVAssetExportSession. could you lend some guidance on how to best save the AVAsset found in PBJVideoView to the user's camera roll?

fyi i'm building an app with "share to instagram" functionality, which is why i need the video in the user's camera roll.

well i don't know why i found that so hard. here's the eventual code i used, in case anyone else is curious:

NSURL *sourceURL = [NSURL URLWithString:videoURLString];
                NSURLSessionTask *download = [[NSURLSession sharedSession] downloadTaskWithURL:sourceURL completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
                    NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
                    NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[sourceURL lastPathComponent]];
                    [[NSFileManager defaultManager] moveItemAtURL:location toURL:tempURL error:nil];
                    UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL);
                }];

                [download resume];