From c75bc3150eed2a520bf2036d82b505d66406ca80 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 16 Dec 2020 15:32:08 +0100 Subject: [PATCH] Add implementation of didFinishProcessingPhoto callback --- packages/camera/camera/CHANGELOG.md | 4 ++++ .../camera/camera/ios/Classes/CameraPlugin.m | 20 +++++++++++++++++++ packages/camera/camera/pubspec.yaml | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 8a7c979c3b72..8009fc49652f 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.0+2 + +* Added implementation of the `didFinishProcessingPhoto` on iOS which allows saving image metadata (EXIF) on iOS 11 and up. + ## 0.6.0+1 Updated README to inform users that iOS 10.0+ is needed for use diff --git a/packages/camera/camera/ios/Classes/CameraPlugin.m b/packages/camera/camera/ios/Classes/CameraPlugin.m index 9455375b8524..133d30f01805 100644 --- a/packages/camera/camera/ios/Classes/CameraPlugin.m +++ b/packages/camera/camera/ios/Classes/CameraPlugin.m @@ -76,6 +76,7 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithData:data].CGImage scale:1.0 orientation:[self getImageRotation]]; + // TODO(sigurdm): Consider writing file asynchronously. bool success = [UIImageJPEGRepresentation(image, 1.0) writeToFile:_path atomically:YES]; if (!success) { @@ -85,6 +86,25 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output _result(_path); } +- (void)captureOutput:(AVCapturePhotoOutput *)output + didFinishProcessingPhoto:(AVCapturePhoto *)photo + error:(NSError *)error API_AVAILABLE(ios(11.0)) { + selfReference = nil; + if (error) { + _result(getFlutterError(error)); + return; + } + + NSData *photoData = [photo fileDataRepresentation]; + + bool success = [photoData writeToFile:_path atomically:YES]; + if (!success) { + _result([FlutterError errorWithCode:@"IOError" message:@"Unable to write file" details:nil]); + return; + } + _result(_path); +} + - (UIImageOrientation)getImageRotation { float const threshold = 45.0; BOOL (^isNearValue)(float value1, float value2) = ^BOOL(float value1, float value2) { diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index cc25133f95f9..3c3e0cea3565 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -2,7 +2,7 @@ name: camera description: A Flutter plugin for getting information about and controlling the camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video, and streaming image buffers to dart. -version: 0.6.0+1 +version: 0.6.0+2 homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera dependencies: