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

FilePicker returns null when running iOS app on macOS (not Catalyst) #25661

Open
follesoe opened this issue Nov 4, 2024 · 2 comments · May be fixed by #25668
Open

FilePicker returns null when running iOS app on macOS (not Catalyst) #25661

follesoe opened this issue Nov 4, 2024 · 2 comments · May be fixed by #25668
Labels
t/bug Something isn't working

Comments

@follesoe
Copy link

follesoe commented Nov 4, 2024

Description

When using the FilePicker API in an iOS application, the PickAsync method returns null (as if canceled) even if the user has not canceled or picked a file.

The same behavior exists in the old Xamarin.Essentials library. On macOS Catalyst, I believe you have worked around the problem by adding in #if !MACCATALYST here: https://github.com/dotnet/maui/blob/main/src/Essentials/src/FilePicker/FilePicker.ios.cs#L41 - which is not present in https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/FilePicker/FilePicker.ios.cs#L35

However, I believe we are getting the "macOS Catalyst" behavior of the UIDocumentPickerViewController when an iOS app runs on an M-series Mac.

One possible solution is using NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac; to detect if the iOS app runs on macOS:

#if !MACCATALYST
			if (documentPicker.PresentationController != null && !NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac)
			{
				documentPicker.PresentationController.Delegate =
					new UIPresentationControllerDelegate(() => GetFileResults(null, tcs));
			}
#endif

Steps to Reproduce

  1. Create a new MAUI application using the FilePicker API
  2. Build for iOS and distribute the app through TestFlight (unfortunately MAUI does not support running iOS apps on macOS directly as per: How to test on Mac (Designed for iPad) or Apple Vision pro? xamarin/xamarin-macios#20868)
  3. See that PickAsync returns null even if file picker is not dismissed.

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.2.24503.2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@follesoe follesoe added the t/bug Something isn't working label Nov 4, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@follesoe
Copy link
Author

follesoe commented Nov 4, 2024

The issues reported by the simular-issues-ai are all relevant but do not cover this case, as they focus on Mac Catalyst, while I believe the same bug exists when running iOS apps that are not Catalyst on macOS.

follesoe added a commit to follesoe/maui that referenced this issue Nov 4, 2024
Fix dotnet#25661 by only assigning the documentPicker.PresentationController.Delegate if the iOS app is not running on Mac. There is already a #if !MACCATALYST check to ensure this code is not compiled for Mac Catalyst apps, but we also need to guard against the same problem for iOS apps running on Mac.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant