Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] add requestFullMetadata for iOS (optional permissions) - iOS changes #5713

Merged

Conversation

PiotrMitkowski
Copy link
Contributor

@PiotrMitkowski PiotrMitkowski commented May 13, 2022

Description

iOS changes for #5915

Related issues

flutter/flutter#65995

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@PiotrMitkowski PiotrMitkowski requested a review from cyanglaz as a code owner May 13, 2022 09:36
@PiotrMitkowski PiotrMitkowski changed the title [image_picker] add requestFullMetadata for iOS (optional permissions) - platform interface [image_picker] add requestFullMetadata for iOS (optional permissions) - iOS changes May 13, 2022
@PiotrMitkowski
Copy link
Contributor Author

@stuartmorgan @cyanglaz I moved iOS specific changes to a separate branch, as suggested.

@@ -16,7 +16,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
image_picker_platform_interface: ^2.3.0
image_picker_platform_interface: ^2.5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.4.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.4.0 was the broken version that I reverted in 2.4.1

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with some minor nits

@@ -119,7 +119,12 @@ - (void)launchPHPickerWithContext:(nonnull FLTImagePickerMethodCallContext *)con
_pickerViewController.presentationController.delegate = self;
self.callContext = context;

[self checkPhotoAuthorizationForAccessLevel];
BOOL requestFullMetadata = context.requestFullMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there's no value to this local variable given how short and readable the right hand side is; you can just inline context.requestFullMetadata into the if condition.

@@ -129,14 +134,24 @@ - (void)launchUIImagePickerWithSource:(nonnull FLTSourceSpecification *)source
imagePickerController.delegate = self;
imagePickerController.mediaTypes = @[ (NSString *)kUTTypeImage ];
self.callContext = context;
BOOL requestFullMetadata = context.requestFullMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Especially since this is only used once, and conditionally, so doesn't make sense to define at such a high level.

@@ -177,6 +179,27 @@ - (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 {
[mockUIImagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]);
}

- (void)testPickImageWithoutFullMetadataPreiOS14 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test pre-14?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that it was a wrong test case, not fully covering the new flag's use case and vulnerable to false positives. I've changed it so it now verifies that there was no check for gallery authorization status.

@@ -227,14 +244,19 @@ - (void)pickVideoWithSource:(nonnull FLTSourceSpecification *)source
}

self.callContext = context;
BOOL requestFullMetadata = context.requestFullMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here; just inline the expression.

@@ -553,8 +575,13 @@ - (void)imagePickerController:(UIImagePickerController *)picker
NSNumber *maxHeight = self.callContext.maxSize.height;
NSNumber *imageQuality = self.callContext.imageQuality;
NSNumber *desiredImageQuality = [self getDesiredImageQuality:imageQuality];
BOOL requestFullMetadata = _callContext.requestFullMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

PHAsset *originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromImagePickerInfo:info];
PHAsset *originalAsset;
if (requestFullMetadata) {
// Full metadata are available only in PHAsset, which requires gallery permission
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing period.

…ermissions-ios-changes

� Conflicts:
�	packages/image_picker/image_picker_ios/CHANGELOG.md
�	packages/image_picker/image_picker_ios/pubspec.yaml
@jmagman
Copy link
Member

jmagman commented May 31, 2022

Friendly bump, looks like the nits were addressed.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more issue I missed last time.

@@ -234,7 +249,11 @@ - (void)pickVideoWithSource:(nonnull FLTSourceSpecification *)source
camera:[self cameraDeviceForSource:source]];
break;
case FLTSourceTypeGallery:
[self checkPhotoAuthorizationWithImagePicker:imagePickerController];
if (context.requestFullMetadata) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need the same @available check and fallback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this change for picking a video can't be used with the current platform interface. It doesn't allow passing requestFullMetadata for both multi-image and videos. I can either improve the interface or remove this change for video picking (depending on what you think is better).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason we wouldn't want support for this in the multi-image case, so updating that interface makes sense.

Looking at the result callback, is this change even relevant for video? It looks like the parameter is only used in a non-video codepath.

Copy link
Contributor Author

@PiotrMitkowski PiotrMitkowski Jun 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll update the interface and create a PR soon. I'll also remove usage of requestFullMetadata for the video path, since it it isn't used, as you've noticed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is still missing the iOS 11 @available check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed usage of requestFullMetadata from here since it isn't supported in the video picking.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM when Stuart's comments are addressed.

@cyanglaz
Copy link
Contributor

@PiotrMitkowski Friendly ping :) Are you planning on continuing this PR?

@PiotrMitkowski
Copy link
Contributor Author

@cyanglaz Sure, I got stuck on waiting for review of this one: #5914, which blocks further work on adding requestFullMetadata flag. I wanted to avoid too much pinging, but I guess it's a good time to post it on Discord :)

@cyanglaz
Copy link
Contributor

I will take a look at #5914

@cyanglaz cyanglaz self-requested a review August 3, 2022 20:47
@PiotrMitkowski
Copy link
Contributor Author

@cyanglaz I've fixed the code based on your latest remarks. Right now, I can't see an option to request your another review, so I'm pinging through this comment :)

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
cc @stuartmorgan

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of small things, but otherwise looks good.

@@ -234,7 +249,11 @@ - (void)pickVideoWithSource:(nonnull FLTSourceSpecification *)source
camera:[self cameraDeviceForSource:source]];
break;
case FLTSourceTypeGallery:
[self checkPhotoAuthorizationWithImagePicker:imagePickerController];
if (context.requestFullMetadata) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is still missing the iOS 11 @available check.

import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

import 'src/messages.g.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this to a package-style import within the same package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was checking if it could fix an issue with imports related to Pigeon, but then I've found a GitHub issue about it and forgot to revert this change. I'll do it now.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 31, 2022
@auto-submit
Copy link

auto-submit bot commented Aug 31, 2022

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 31, 2022
@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 31, 2022
@auto-submit auto-submit bot merged commit ef20791 into flutter:main Aug 31, 2022
@PiotrMitkowski PiotrMitkowski deleted the ios-optional-permissions-ios-changes branch August 31, 2022 13:58
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 31, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 31, 2022
@idish
Copy link

idish commented Sep 13, 2022

Thanks for the great work!
Is there any schedule for the 0.8.6 version to be published? Really looking forward to it.

@jmagman
Copy link
Member

jmagman commented Sep 13, 2022

It's already available, note it's image_picker_ios https://pub.dev/packages/image_picker_ios/changelog#086

@stuartmorgan
Copy link
Contributor

The PR you'll want to follow to know when you can use this feature as a plugin client is #5915

@idish
Copy link

idish commented Sep 14, 2022

Just tried to implement that in my app and seems as it crashes due to permission issue after picking photos.
I think it worth noting that here as well. See my comment:
#5915 (comment)

adam-harwood pushed a commit to adam-harwood/flutter_plugins that referenced this pull request Nov 3, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: image_picker platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants