From 28de3646e75e0fb5c470ce474b905c99ba4cf793 Mon Sep 17 00:00:00 2001 From: Tenkai Ruri Date: Thu, 21 Feb 2019 10:18:46 +0800 Subject: [PATCH] Fix image picker record video has two files on IOS --- packages/image_picker/CHANGELOG.md | 4 ++++ packages/image_picker/ios/Classes/ImagePickerPlugin.m | 8 +++++--- packages/image_picker/pubspec.yaml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/image_picker/CHANGELOG.md b/packages/image_picker/CHANGELOG.md index b7a9538fc714..5059bb4a62f5 100644 --- a/packages/image_picker/CHANGELOG.md +++ b/packages/image_picker/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.0+4 + +* Fixed record video has two files on IOS. + ## 0.5.0+3 * Fixed am Android crash when Image Picker is registered without an activity. diff --git a/packages/image_picker/ios/Classes/ImagePickerPlugin.m b/packages/image_picker/ios/Classes/ImagePickerPlugin.m index ea7ee2cf1ee0..b49c2633fdf7 100644 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -136,17 +136,19 @@ - (void)imagePickerController:(UIImagePickerController *)picker return; } if (videoURL != nil) { - NSData *data = [NSData dataWithContentsOfURL:videoURL]; NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString]; NSString *tmpFile = [NSString stringWithFormat:@"image_picker_%@.MOV", guid]; NSString *tmpDirectory = NSTemporaryDirectory(); NSString *tmpPath = [tmpDirectory stringByAppendingPathComponent:tmpFile]; + NSString *videoPath = [videoURL.absoluteString stringByReplacingOccurrencesOfString:@"file://" + withString:@""]; + NSError *error = nil; - if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:data attributes:nil]) { + if ([[NSFileManager defaultManager] moveItemAtPath:videoPath toPath:tmpPath error:&error]) { _result(tmpPath); } else { _result([FlutterError errorWithCode:@"create_error" - message:@"Temporary file could not be created" + message:[NSString stringWithFormat:@"%@", error] details:nil]); } } else { diff --git a/packages/image_picker/pubspec.yaml b/packages/image_picker/pubspec.yaml index 226c9f1d5ae7..7a6ac9da6b21 100755 --- a/packages/image_picker/pubspec.yaml +++ b/packages/image_picker/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Flutter Team - Rhodes Davis Jr. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker -version: 0.5.0+3 +version: 0.5.0+4 flutter: plugin: