Renaming a file using UISaveVideoAtPathToSavedPhotosAlbum?

but I want to download the video from the URL and to rename the file of this video before saving it. Use UISaveVideoAtPathToSavedPhotosAlbum any help .. what do I need to do

 NSData *imageData = [NSData dataWithContentsOfURL:[NSURL  
 URLWithString:@"www.xyz.com/image.mp4"]];
+3
source share
2 answers

You would do something like this:

- (void) downloadVideo
   NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.xyz.com/image.mp4"]];
   NSString *tempPath = [NSString stringWithFormat:@"%@/%@", NSTemporaryDirectory(), temp.mp4];
   [imageData writeToFile:tempPath atomically:NO];
   UISaveVideoAtPathToSavedPhotosAlbum (@ tempPath, self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
);

- (void) video: (NSString *) videoPath
    didFinishSavingWithError: (NSError *) error
    contextInfo: (void *) contextInfo {
  NSLog(@"Finished saving video with error: %@", error);
}

There are two things to consider:

  • Make sure you provide the URL scheme. This is not a browser, it is not going to try to autocomplete http and guess about you.
  • , dataWithContentsOfURL:. 20 , , . , , , NSURLConnection.
+4

Source: https://habr.com/ru/post/1722410/


All Articles