Skip to content

[iOS/MacCatalyst] Use newer API in FilePicker #27521

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

Conversation

MartyIX
Copy link
Contributor

@MartyIX MartyIX commented Feb 2, 2025

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Feb 2, 2025
{
PickHandler = urls => GetFileResults(urls, tcs)
};
documentPicker.DidPickDocumentAtUrls += (_, e) => GetFileResults(e.Urls, tcs);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My hope is that the original issue is fixed by using this API.

Copy link

Choose a reason for hiding this comment

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

Have you checked how OperatingSystem.IsIOS() is implemented?

Copy link

@follesoe follesoe Feb 2, 2025

Choose a reason for hiding this comment

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

The OperatingSystem.IsIOS will return true for an iOS app running on macOS (as it is implemented using compile flags), and can only be used to determine if it is a Catalyst app or an iOS app, not if it is an iOS app on macOS.

But it could be that DidPickDocumentAtUrls is behaving correctly for iOS apps running on macOS, unlike the documentPicker.PresentationController.Delegate which is the root cause of the issue today when running iOS MAUI apps on macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this is not correct. I updated 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.

But it could be that DidPickDocumentAtUrls is behaving correctly for iOS apps running on macOS, unlike the documentPicker.PresentationController.Delegate which is the root cause of the issue today when running iOS MAUI apps on macOS.

Yes, that's what I aim for. It can be tested once there are nugets generated by CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The nugets are here: https://dev.azure.com/xamarin/public/_build/results?buildId=134094&view=artifacts&pathAsName=false&type=publishedArtifacts

See "nugets" and click the three dots to download it.

To use the nugets, I believe you need to add Nuget.config in your root project like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Local nuget packages" value="../LocalNugetPackages" />
  </packageSources>
</configuration>

and put the nugets in the LocalNugetPackages folder and set MauiVersion in a MAUI .csproj file:

<MauiVersion>9.0.40-ci.main.25102.1</MauiVersion>

I believe this should work. Don't mind this post, if you know all this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@follesoe Did you have a chance to test this PR?

Copy link

Choose a reason for hiding this comment

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

@MartyIX Not yet, but working on our MAUI migration project right now. I will see if I manage to get around to it. Just so many other tasks on my plate 😫

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 believe the nugets will get deleted on the server in one month. So there is some time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@follesoe Any chance you had some time to test this? If the PR fixes your issue, then there is a bigger chance that this PR will be accepted.

@MartyIX MartyIX marked this pull request as ready for review February 2, 2025 13:26
@MartyIX MartyIX requested a review from a team as a code owner February 2, 2025 13:26
documentPicker.PresentationController.Delegate =
new UIPresentationControllerDelegate(() => GetFileResults(null, tcs));
}
if (documentPicker.PresentationController != null && !(OperatingSystem.IsIOSVersionAtLeast(14, 0) && NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to fix #25661

@PureWeen
Copy link
Member

PureWeen commented Feb 2, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis added this to the .NET 9 SR5 milestone Feb 19, 2025
@PureWeen PureWeen merged commit b17db5e into dotnet:main Feb 19, 2025
130 checks passed
@MartyIX MartyIX deleted the feature/2025-02-02-MacCatalyst-FilePicker-improvements branch February 19, 2025 22:15
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community ✨ Community Contribution
Projects
Status: Done
4 participants