LoginSignup
15
12

More than 5 years have passed since last update.

[iOS] [Objective-C] S3の動画をカメラロールに保存する

Last updated at Posted at 2014-06-10

iPhoneシミュレーターだと「The operation could not be completed.」と言われて失敗するが
実機だと保存できている。

NSURL *sourceURL = [NSURL URLWithString:@"https://s3.amazonaws.com/〜動画のpath〜.mp4"];
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];
15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12