Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISaveVideoAtPathToSavedPhotosAlbum not saving video to camera roll

I'm trying to use glimpse to record a UIView. It successfully saves it to the app's documents folder, however I also need it to save to the user's camera roll. It isn't saving to the camera roll, I am presented with an alert to allow the app to access my camera roll but it's not saving in any albums.

I've tried a decent amount of code ranging from this:

[self.glimpse startRecordingView:self.view onCompletion:^(NSURL *fileOuputURL) {
        NSLog(@"DONE WITH OUTPUT: %@", fileOuputURL.absoluteString);


      UISaveVideoAtPathToSavedPhotosAlbum(fileOuputURL.absoluteString,nil,nil,nil);





    }];

To this:

 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library writeVideoAtPathToSavedPhotosAlbum:fileOuputURL
                                    completionBlock:^(NSURL *assetURL, NSError *error){NSLog(@"hello");}];

The log prints but it doesn't save the video to the camera roll.

If someone has any idea on my this isn't work please let me know! Thanks!

like image 406
Jack Avatar asked Dec 09 '25 00:12

Jack


2 Answers

The issue is with video path provided. Provide the relative path from the url.

if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileUrl.relativePath) {
    UISaveVideoAtPathToSavedPhotosAlbum(fileUrl.relativePath, nil, nil, nil)
}

If you had added this UIVideoAtPathIsCompatibleWithSavedPhotosAlbum check the compiler would have shown you the issue with the file.

like image 158
Vipin Johney Avatar answered Dec 10 '25 17:12

Vipin Johney


Issue is your video path given as URL,So you have to check wheather your URL Path is compactible to save in video or not, and if you want to save video in camara roll then just pass the URL and follow this code:

-(void)saveVideo:(NSString *)videoData withCallBack:(void(^)(id))callBack{
library = [[ALAssetsLibrary alloc] init];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSData *yourVideoData=[NSData dataWithContentsOfURL:[NSURL URLWithString:videoData]];
    if (yourVideoData) {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"video.mp4"];


                 if([yourVideoData writeToFile:filePath atomically:YES])
                 {
                     NSURL *capturedVideoURL = [NSURL URLWithString:filePath];
                    //Here you can check video is compactible to store in gallary or not
                     if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:capturedVideoURL]) {
                         // request to save video in photo roll.
                         [library writeVideoAtPathToSavedPhotosAlbum:capturedVideoURL completionBlock:^(NSURL *assetURL, NSError *error) {
                             if (error) {
                                 callBack(@"error while saving video");
                                 NSLog(@"error while saving video");
                             } else{

                                     callBack(@"Video has been saved in to album successfully !!!");

                    }
                         }];
                     }
                }

    }
});


}
like image 24
khusboo suhasini Avatar answered Dec 10 '25 18:12

khusboo suhasini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!