From 8d32d1f0b987d09f65204848422b57d2619b629b 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 cb8dfedd1d9a..a9e53936e807 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.1 + +* Added implementation of the `didFinishProcessingPhoto` on iOS which allows saving image metadata (EXIF) on iOS 11 and up. + ## 0.6.0 As part of implementing federated architecture and making the interface compatible with the web this version contains the following **breaking changes**: 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 64d5bba61159..d82c445612ff 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 +version: 0.6.1 homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera dependencies: