Search code examples
iosobjective-ciphonevideoinstagram-api

Cannot download Instagram video to camera roll


I am trying to learn the Instagram API and I want to be able to save images and video content to my camera roll. So far the images code works properly but I cant get the video to save to camera roll. Here is my code so far

- (void)downloadButtonPressed:(UIButton *)sender {
if ([self.mediaModel.mediaType isEqualToString:@"video"]) {
    NSURL *videoURL = [NSURL URLWithString:_mediaModel.videoStandardResolutionURL];
    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoURL.path)) {
        NSLog(@"compatible");
    } else {
        NSLog(@"not compatible");
    }
    //UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);
} else {
    UIImageWriteToSavedPhotosAlbum(self.imageView.image, nil, nil, nil);
}

}

First I check is the media type is a video or not. If not then the image is straightforward to save.

If not I check if the videoURL.path is compatible but this is where I get stuck and I get an error like this:

Video /hphotos-xaf1/t50.2886-16/11803693_1632141970376671_10815617_n.mp4 cannot be saved to the saved photos album: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo=0x7f8b48f25d00 {NSUnderlyingError=0x7f8b48f39f90 "The operation couldn’t be completed. No such file or directory", NSErrorFailingURLStringKey=file:///hphotos-xaf1/t50.2886-16/11803693_1632141970376671_10815617_n.mp4, NSErrorFailingURLKey=file:///hphotos-xaf1/t50.2886-16/11803693_1632141970376671_10815617_n.mp4, NSURL=file:///hphotos-xaf1/t50.2886-16/11803693_1632141970376671_10815617_n.mp4, NSLocalizedDescription=The requested URL was not found on this server.}

Would really appreciate the help. Thanks alot!


Solution

  • Don't try to save it directly from the network into the saved photos album. Download it (using NSURLSession and a download task). Then save it from there (i.e., from the local file URL that this gives you) into the saved photos album.