From bfa38fed2c9141d614ebbbe5786f3904f7a90202 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 15 Apr 2020 11:41:21 +0200 Subject: [PATCH] fix(ios): return copy of video when picking from gallery on iOS 13 (#580) --- src/ios/CDVCamera.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index edc613e..d4c084b 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -513,9 +513,22 @@ static NSString* toBase64(NSData* data) { - (CDVPluginResult*)resultForVideo:(NSDictionary*)info { NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString]; + // On iOS 13 the movie path becomes inaccessible, create and return a copy + if (IsAtLeastiOSVersion(@"13.0")) { + moviePath = [self createTmpVideo:[[info objectForKey:UIImagePickerControllerMediaURL] path]]; + } return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:moviePath]; } +- (NSString *) createTmpVideo:(NSString *) moviePath { + NSString* moviePathExtension = [moviePath pathExtension]; + NSString* copyMoviePath = [self tempFilePath:moviePathExtension]; + NSFileManager* fileMgr = [[NSFileManager alloc] init]; + NSError *error; + [fileMgr copyItemAtPath:moviePath toPath:copyMoviePath error:&error]; + return [[NSURL fileURLWithPath:copyMoviePath] absoluteString]; +} + - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { __weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;