Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[image_picker] Removes use of PHAsset when using PHPickerViewController #8020

Closed
wants to merge 4 commits into from

Conversation

WenHaozhan
Copy link
Contributor

@WenHaozhan WenHaozhan commented Nov 5, 2024

Fixes issue flutter/flutter#90373

Currently on IOS 14+, images are picked using PHPickerViewController which does not need photo permissions and also gets the full image metadata regardless of requestFullMetadata. However, it currently retrieves the metadata using PHAsset which does require permission and causes the gallery opening twice issue. Another issue is that an error is thrown when permission is denied even if none are required.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@stuartmorgan stuartmorgan added the triage-ios Should be looked at in iOS triage label Nov 8, 2024
@WenHaozhan WenHaozhan force-pushed the main branch 2 times, most recently from 78db413 to b051146 Compare November 15, 2024 19:58
@WenHaozhan
Copy link
Contributor Author

Any update on this?

@loic-sharma
Copy link
Member

@WenHaozhan Hello, this is on my queue to review. I'm not familiar with the image picker plugin yet and need to ramp up first before I'm able to review. I apologize for the delay.

@loic-sharma
Copy link
Member

loic-sharma commented Nov 26, 2024

Hello, I'm ramping up and trying to understand the situation. My understanding:

  1. Apple introduced PHPicker to let an app pick images without permissions to the photo library. See WWDC 2020

  2. [image_picker] Image picker phpicker impl plugins#3835 added a PHPicker implementation to image_picker_ios for iOS 14+.

    However, it used PHPicker only to pick images, not to load them. The PR continued to use PHAsset to load images, which requires permissions to the user's library.

  3. [image_picker] add requestFullMetadata for iOS (optional permissions) - platform interface changes for multi image picking plugins#5914 and [image_picker] Allow saving photos picked with PHPicker without permissions plugins#6429 introduced ImageOptions.requestFullMetadata.

    If requestFullMetadata is set to false, the iOS app no longer needs permissions to the user's library as PHAsset is no longer used the load the image. However, it's not clear what metadata - if any - is lost if requestFullMetadata is false.

  4. This PR removes PHAsset entirely from the PHPPicker code path.

@vashworth's message in flutter/flutter#90373 (comment) indicates animated GIFs are a concern. I've verified that this PR is still able to load & animate GIFs as expected.

@stuartmorgan @jmagman Would you have any recommendations on things we should check before landing this change? AFAICT, this change appears to be correct.

@@ -529,11 +529,19 @@ - (void)testPickImageAuthorizationDenied API_AVAILABLE(ios(14)) {
quality:nil
fullMetadata:YES
completion:^(NSString *result, FlutterError *error) {
// Does not error due to access denied
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove this test entirely as this is no longer a concern?

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 removed this test.

@@ -113,11 +113,7 @@ - (void)launchPHPickerWithContext:(nonnull FLTImagePickerMethodCallContext *)con
pickerViewController.presentationController.delegate = self;
self.callContext = context;

if (context.requestFullMetadata) {
[self checkPhotoAuthorizationWithPHPicker:pickerViewController];
Copy link
Member

Choose a reason for hiding this comment

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

Does anything use checkPhotoAuthorizationWithPHPicker now? Can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think anything uses this, removed.

// Only if requested, fetch the full "PHAsset" metadata, which requires "Photo Library Usage"
// permissions.
if (self.requestFullMetadata) {
originalAsset = [FLTImagePickerPhotoAssetUtil getAssetFromPHPickerResult:self.result];
Copy link
Member

Choose a reason for hiding this comment

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

Does anything use getAssetFromPHPickerResult now? Can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed function and a test that uses it.

@WenHaozhan WenHaozhan reopened this Nov 26, 2024
WenHaozhan and others added 2 commits November 25, 2024 22:44
Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
@@ -499,7 +499,7 @@ - (void)testPickImageRequestAuthorization API_AVAILABLE(ios(14)) {
id mockPhotoLibrary = OCMClassMock([PHPhotoLibrary class]);
Copy link
Member

Choose a reason for hiding this comment

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

Should we rename this test to something like testPickImageDoesntRequestAuthorization?

@domesticmouse domesticmouse removed their request for review November 27, 2024 04:29
@domesticmouse
Copy link
Contributor

I'm not required now that flutter_svg and flutter_markdown have been removed

@WenHaozhan
Copy link
Contributor Author

Hey, sorry about this, I messed up a rebase. I will create a new pull request.

@WenHaozhan WenHaozhan closed this Nov 27, 2024
auto-submit bot pushed a commit that referenced this pull request Jan 3, 2025
Original PR #8020
Fixes issue flutter/flutter#90373

Currently on IOS 14+, images are picked using `PHPickerViewController` which does not need photo permissions and also gets the full image metadata regardless of `requestFullMetadata`. However, it currently retrieves the metadata using `PHAsset` which does require permission and causes the gallery opening twice issue. Another issue is that an error is thrown when permission is denied even if none are required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: image_picker platform-ios triage-ios Should be looked at in iOS triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants