Skip to content

[image_picker_ios] Add photo to simulator Photos library during test #9759

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

Merged
merged 7 commits into from
Aug 15, 2025

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Aug 6, 2025

The iOS 26 simulator Photos library does not pre-populate example images.
When the example app launches, add a test photo to the library. Only add a photo on first launch of the example app, enforced for a NSUserDefault.

Fixes flutter/flutter#173327

Pre-Review Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a test photo to the iOS simulator's Photos library on app launch to ensure UI tests can run on newer iOS versions where the library is empty. I've provided feedback on AppDelegate.m to improve robustness by checking authorization status and to fix code formatting. Additionally, I've pointed out a small typo in the CHANGELOG.md.

Comment on lines 13 to 44
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];

if (@available(iOS 14, *)) {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
__block NSError *saveError = nil;
[PHPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelAddOnly handler:^(PHAuthorizationStatus status) {
if (![PHPhotoLibrary.sharedPhotoLibrary performChangesAndWait:^{
NSURL *jpgImageTall = [bundle URLForResource:@"jpgImageTall" withExtension:@"jpg"];
[PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:jpgImageTall];
} error:&saveError]) {
os_log_error(OS_LOG_DEFAULT, "%@", saveError);
}
}];
}
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Choose a reason for hiding this comment

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

medium

Consider checking the PHAuthorizationStatus returned in the handler before attempting to save the photo. This would make the logic clearer and avoid an unexpected failure if permissions are denied. Also, the indentation in this method is inconsistent with the project's style.1

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [GeneratedPluginRegistrant registerWithRegistry:self];

    if (@available(iOS 14, *)) {
        NSBundle *bundle = [NSBundle bundleForClass:[self class]];
        __block NSError *saveError = nil;
        [PHPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelAddOnly handler:^(PHAuthorizationStatus status) {
            if (status == PHAuthorizationStatusAuthorized) { // Check authorization status
                if (![PHPhotoLibrary.sharedPhotoLibrary performChangesAndWait:^{
                    NSURL *jpgImageTall = [bundle URLForResource:@"jpgImageTall" withExtension:@"jpg"];
                    [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL:jpgImageTall];
                } error:&saveError]) {
                    os_log_error(OS_LOG_DEFAULT, "%@", saveError);
                }
            } else {
                os_log(OS_LOG_DEFAULT, "Photos authorization not granted");
            }
        }];
    }
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Style Guide References

Footnotes

  1. Code should follow relevant style guides and use auto-formatters to ensure consistency. (link)

Copy link
Member Author

Choose a reason for hiding this comment

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

Consider checking the PHAuthorizationStatus returned in the handler before attempting to save the photo.

This is fine for a test app where we know our permission handler will do the right thing.

the indentation in this method is inconsistent with the project's style

Very true, waiting on the clang formatter to run.

@@ -15,23 +15,14 @@
3A72BAD3FAE6E0FA9D80826B /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 35AE65F25E0B8C8214D8372B /* libPods-RunnerTests.a */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
5C9513011EC38BD300040975 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C9513001EC38BD300040975 /* GeneratedPluginRegistrant.m */; };
680049382280F2B9006DD6AB /* pngImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 680049352280F2B8006DD6AB /* pngImage.png */; };
Copy link
Member Author

Choose a reason for hiding this comment

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

The test images were being included in the RunnerUITest target, and were unused. Remove it.

BE6173D826A958B800D0974D /* ImagePickerFromLimitedGalleryUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = BE6173D726A958B800D0974D /* ImagePickerFromLimitedGalleryUITests.m */; };
F4F7A436CCA4BF276270A3AE /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EC32F6993F4529982D9519F1 /* libPods-Runner.a */; };
F706BF732E433163001263B9 /* jpgImageTall.jpg in Resources */ = {isa = PBXBuildFile; fileRef = F706BF722E433163001263B9 /* jpgImageTall.jpg */; };
Copy link
Member Author

Choose a reason for hiding this comment

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

Include all test images to the example app resources (not just the RunnerTest unit test app) so they can be added when the app finishes launching. Right now only one is added, but I can see someone in the future trying to add a new one and being confused why the URL is nil.
These images are very small.

@jmagman jmagman changed the title [image_picker] Add photo to simulator Photos app during test [image_picker] Add photo to simulator Photos library during test Aug 6, 2025
@jmagman jmagman changed the title [image_picker] Add photo to simulator Photos library during test [image_picker_ios] Add photo to simulator Photos library during test Aug 6, 2025
@jmagman
Copy link
Member Author

jmagman commented Aug 6, 2025

There's still one failure on Xcode 26:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8707266248916852641/+/u/Run_package_tests/native_test/stdout

error: -[ImagePickerFromLimitedGalleryUITests testSelectingFromGallery] : Failed to not hittable: Image, {{0.0, 297.0}, {128.9, 129.0}}, label: 'Photo, August 06, 10:41 AM'

https://storage.googleapis.com/flutter_logs/flutter/269ff996-7acf-45ab-b134-a2779612650f/native%20test/269ff996-7acf-45ab-b134-a2779612650f/xcodebuild-2025-08-06T10:43:40.234490.zip

Screenshot 2025-08-06 at 12 41 59 PM

@jmagman jmagman force-pushed the image-picker-ios-26 branch from 238246a to f452ca2 Compare August 14, 2025 05:14
@jmagman jmagman marked this pull request as ready for review August 14, 2025 05:52
@jmagman jmagman mentioned this pull request Aug 14, 2025
Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

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

LGTM

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2025
@auto-submit auto-submit bot merged commit f9bd733 into flutter:main Aug 15, 2025
80 checks passed
@jmagman jmagman deleted the image-picker-ios-26 branch August 15, 2025 22:34
CaoGiaHieu-dev added a commit to CaoGiaHieu-dev/packages that referenced this pull request Aug 18, 2025
* main: (24 commits)
  Roll Flutter from 0a2906b81d5e to b3fb4c786d80 (5 revisions) (flutter#9840)
  Update repo for 3.35 stable release (flutter#9816)
  Roll Flutter from 52af7a504025 to 0a2906b81d5e (16 revisions) (flutter#9836)
  [image_picker] Updates min SDK to 3.29 (flutter#9830)
  [image_picker] Add the ability to pick multiple videos (flutter#9775)
  [image_picker] Add the ability to pick multiple videos - platform implementations (flutter#9818)
  [various] Updates min SDK for third_party/packages to 3.29 (flutter#9819)
  [vector_graphics] Updates min SDK to 3.29 (flutter#9820)
  [google_maps_flutter] Updates min SDK to 3.29 (flutter#9821)
  [video_player] Updates min SDK to 3.29 (flutter#9826)
  [shared_preferences] Updates min SDK to 3.29 (flutter#9829)
  [image_picker_ios] Add photo to simulator Photos library during test (flutter#9759)
  [interactive_media_ads] Updates `README` with information about enabling desugaring on Android (flutter#9790)
  [in_app_purchase] Updates min SDK to 3.29 (flutter#9825)
  Roll Flutter from f4334d27934b to 52af7a504025 (29 revisions) (flutter#9832)
  [go_router] Update generated output format (flutter#9817)
  [video_player] Move Android buffer updates to Dart (flutter#9771)
  [webview_flutter] Add support for payment requests on Android (flutter#9679)
  [vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (flutter#9813)
  [url_launcher_ios] Fix test button text to work on iOS 26 (flutter#9766)
  ...

# Conflicts:
#	packages/go_router_builder/CHANGELOG.md
#	packages/go_router_builder/example/lib/all_types.g.dart
#	packages/go_router_builder/example/lib/main.g.dart
#	packages/go_router_builder/example/lib/shell_route_with_keys_example.g.dart
#	packages/go_router_builder/example/lib/shell_route_with_observers_example.g.dart
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 19, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 19, 2025
flutter/packages@5c52c55...953cae0

2025-08-19 magder@google.com Add com.android.tools.build:gradle to
dependabot gradle-plugin group (flutter/packages#9848)
2025-08-19 stuartmorgan@google.com [flutter_migrate] Remove source
(flutter/packages#9847)
2025-08-18 lukas.mirbt1@gmail.com [go_router]: Add `RelativeGoRouteData`
and `TypedRelativeGoRoute` (flutter/packages#9732)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter (stable) from
edada7c to 20f8274 (1474 revisions) (flutter/packages#9837)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter from
b3fb4c7 to 2265d94 (7 revisions) (flutter/packages#9845)
2025-08-18 stuartmorgan@google.com Disable SwiftPM for `xcode-analyze`
(flutter/packages#9666)
2025-08-17 engine-flutter-autoroll@skia.org Roll Flutter from
0a2906b to b3fb4c7 (5 revisions) (flutter/packages#9840)
2025-08-16 stuartmorgan@google.com Update repo for 3.35 stable release
(flutter/packages#9816)
2025-08-16 engine-flutter-autoroll@skia.org Roll Flutter from
52af7a5 to 0a2906b (16 revisions) (flutter/packages#9836)
2025-08-16 stuartmorgan@google.com [image_picker] Updates min SDK to
3.29 (flutter/packages#9830)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos (flutter/packages#9775)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos - platform implementations (flutter/packages#9818)
2025-08-16 stuartmorgan@google.com [various] Updates min SDK for
third_party/packages to 3.29 (flutter/packages#9819)
2025-08-16 stuartmorgan@google.com [vector_graphics] Updates min SDK to
3.29 (flutter/packages#9820)
2025-08-16 stuartmorgan@google.com [google_maps_flutter] Updates min SDK
to 3.29 (flutter/packages#9821)
2025-08-16 stuartmorgan@google.com [video_player] Updates min SDK to
3.29 (flutter/packages#9826)
2025-08-15 stuartmorgan@google.com [shared_preferences] Updates min SDK
to 3.29 (flutter/packages#9829)
2025-08-15 magder@google.com [image_picker_ios] Add photo to simulator
Photos library during test (flutter/packages#9759)
2025-08-15 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Updates `README` with information about enabling
desugaring on Android (flutter/packages#9790)
2025-08-15 stuartmorgan@google.com [in_app_purchase] Updates min SDK to
3.29 (flutter/packages#9825)
2025-08-15 engine-flutter-autoroll@skia.org Roll Flutter from
f4334d2 to 52af7a5 (29 revisions) (flutter/packages#9832)
2025-08-15 stuartmorgan@google.com [go_router] Update generated output
format (flutter/packages#9817)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
WillBLogical pushed a commit to WillBLogical/packages that referenced this pull request Aug 20, 2025
…lutter#9759)

The iOS 26 simulator Photos library does not pre-populate example images.
When the example app launches, add a test photo to the library. Only add a photo on first launch of the example app, enforced for a `NSUserDefault`.

Fixes flutter/flutter#173327

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 22, 2025
…er#174040)

flutter/packages@5c52c55...953cae0

2025-08-19 magder@google.com Add com.android.tools.build:gradle to
dependabot gradle-plugin group (flutter/packages#9848)
2025-08-19 stuartmorgan@google.com [flutter_migrate] Remove source
(flutter/packages#9847)
2025-08-18 lukas.mirbt1@gmail.com [go_router]: Add `RelativeGoRouteData`
and `TypedRelativeGoRoute` (flutter/packages#9732)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter (stable) from
edada7c to 20f8274 (1474 revisions) (flutter/packages#9837)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter from
b3fb4c7 to 2265d94 (7 revisions) (flutter/packages#9845)
2025-08-18 stuartmorgan@google.com Disable SwiftPM for `xcode-analyze`
(flutter/packages#9666)
2025-08-17 engine-flutter-autoroll@skia.org Roll Flutter from
0a2906b to b3fb4c7 (5 revisions) (flutter/packages#9840)
2025-08-16 stuartmorgan@google.com Update repo for 3.35 stable release
(flutter/packages#9816)
2025-08-16 engine-flutter-autoroll@skia.org Roll Flutter from
52af7a5 to 0a2906b (16 revisions) (flutter/packages#9836)
2025-08-16 stuartmorgan@google.com [image_picker] Updates min SDK to
3.29 (flutter/packages#9830)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos (flutter/packages#9775)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos - platform implementations (flutter/packages#9818)
2025-08-16 stuartmorgan@google.com [various] Updates min SDK for
third_party/packages to 3.29 (flutter/packages#9819)
2025-08-16 stuartmorgan@google.com [vector_graphics] Updates min SDK to
3.29 (flutter/packages#9820)
2025-08-16 stuartmorgan@google.com [google_maps_flutter] Updates min SDK
to 3.29 (flutter/packages#9821)
2025-08-16 stuartmorgan@google.com [video_player] Updates min SDK to
3.29 (flutter/packages#9826)
2025-08-15 stuartmorgan@google.com [shared_preferences] Updates min SDK
to 3.29 (flutter/packages#9829)
2025-08-15 magder@google.com [image_picker_ios] Add photo to simulator
Photos library during test (flutter/packages#9759)
2025-08-15 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Updates `README` with information about enabling
desugaring on Android (flutter/packages#9790)
2025-08-15 stuartmorgan@google.com [in_app_purchase] Updates min SDK to
3.29 (flutter/packages#9825)
2025-08-15 engine-flutter-autoroll@skia.org Roll Flutter from
f4334d2 to 52af7a5 (29 revisions) (flutter/packages#9832)
2025-08-15 stuartmorgan@google.com [go_router] Update generated output
format (flutter/packages#9817)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 22, 2025
…er#174040)

flutter/packages@5c52c55...953cae0

2025-08-19 magder@google.com Add com.android.tools.build:gradle to
dependabot gradle-plugin group (flutter/packages#9848)
2025-08-19 stuartmorgan@google.com [flutter_migrate] Remove source
(flutter/packages#9847)
2025-08-18 lukas.mirbt1@gmail.com [go_router]: Add `RelativeGoRouteData`
and `TypedRelativeGoRoute` (flutter/packages#9732)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter (stable) from
edada7c to 20f8274 (1474 revisions) (flutter/packages#9837)
2025-08-18 engine-flutter-autoroll@skia.org Roll Flutter from
b3fb4c7 to 2265d94 (7 revisions) (flutter/packages#9845)
2025-08-18 stuartmorgan@google.com Disable SwiftPM for `xcode-analyze`
(flutter/packages#9666)
2025-08-17 engine-flutter-autoroll@skia.org Roll Flutter from
0a2906b to b3fb4c7 (5 revisions) (flutter/packages#9840)
2025-08-16 stuartmorgan@google.com Update repo for 3.35 stable release
(flutter/packages#9816)
2025-08-16 engine-flutter-autoroll@skia.org Roll Flutter from
52af7a5 to 0a2906b (16 revisions) (flutter/packages#9836)
2025-08-16 stuartmorgan@google.com [image_picker] Updates min SDK to
3.29 (flutter/packages#9830)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos (flutter/packages#9775)
2025-08-16 stuartmorgan@google.com [image_picker] Add the ability to
pick multiple videos - platform implementations (flutter/packages#9818)
2025-08-16 stuartmorgan@google.com [various] Updates min SDK for
third_party/packages to 3.29 (flutter/packages#9819)
2025-08-16 stuartmorgan@google.com [vector_graphics] Updates min SDK to
3.29 (flutter/packages#9820)
2025-08-16 stuartmorgan@google.com [google_maps_flutter] Updates min SDK
to 3.29 (flutter/packages#9821)
2025-08-16 stuartmorgan@google.com [video_player] Updates min SDK to
3.29 (flutter/packages#9826)
2025-08-15 stuartmorgan@google.com [shared_preferences] Updates min SDK
to 3.29 (flutter/packages#9829)
2025-08-15 magder@google.com [image_picker_ios] Add photo to simulator
Photos library during test (flutter/packages#9759)
2025-08-15 10687576+bparrishMines@users.noreply.github.com
[interactive_media_ads] Updates `README` with information about enabling
desugaring on Android (flutter/packages#9790)
2025-08-15 stuartmorgan@google.com [in_app_purchase] Updates min SDK to
3.29 (flutter/packages#9825)
2025-08-15 engine-flutter-autoroll@skia.org Roll Flutter from
f4334d2 to 52af7a5 (29 revisions) (flutter/packages#9832)
2025-08-15 stuartmorgan@google.com [go_router] Update generated output
format (flutter/packages#9817)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

image_picker_ios tests crash failing on Xcode 26 beta 4: Failed due to not able to find an image with 30 seconds
2 participants