-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 on MacCatalyst app is not working (occasionally) #15126
Comments
Hi @petervaradi. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
There is a duplicate bug I just found: |
Similar thing happening on iOS 16.1.1 using FilePicker.PickMultipleAsync when debugging a remote device, but the enumerable is empty instead of null. Due to its inconsistent nature, I cannot fully confirm it only happens in debug mode, but so far it seems to be the case. |
I am having this issue on MacOs using PickMultipleAsync It works in dev but does not work after deploying via TestFlight, its works on PC deployed via windows store. This component does pretty much one thing, how is taking so long to fix? (considering the original issue #11088) I have tried the dependency injection and direct calls, is there any definitive fix or work around? or is this a capabilities settings? CommunityToolkit.Maui 5.2.0 |
I ended up using this as a workaround: |
Thanks for the link, however I tried this but gives me the filename not the full path to the file and its no longer supported as per the issue that also mentions this problem. Did you have this issue? UPDATE: I forked that repro and fixed it [tested via TestFlight], forked version here: https://github.com/brightertools/MauiFilePicker |
Verified this on Visual Studio Enterprise 17.9.0 Preview 1(8.0.3). Repro on MacCatalyst, not repro on Windows 11, Android 14.0-API34 and iOS 17.0 with below Project: |
I ran into this as well. MacOS does not work with the FilePicker. |
Any official update on this? This is blocking our progress rn. Picking a file is one of the first things users have to do when using our app :\ |
@datvm I see you have a fix in your plugin and mentioned maybe doing a PR, I guess you never got to that? Would you be able to point out what the difference is between your code and ours and give a hint where this might originate? |
@jfversluis hi, isn't there a fix (and explanation of the problem) posted in #11088 already (this comment)? Is this a different one? It's been a while but IIRC my library simply rewrites the logic for file picker for iOS and Mac Catalyst from scratch in this file. I didn't rely on MAUI code at the time so I am not really sure the difference. Also an update that I am back to MAUI development in the recent months, time to revisit this issue I think. |
Yeah just hitted this too. |
Omg this is one of my main functionality of my app 😂 and my only way to develop is thru a macbook can anyone suggest for workaround? |
I made this small gist and it did the trick for me. using UIKit;
using UniformTypeIdentifiers;
#nullable enable
namespace MyServices
{
public partial class MacFilePicker
{
public static async Task<FileResult?> PickAsync(PickOptions options)
{
var tcs = new TaskCompletionSource<string>();
var utTypes = options.FileTypes?.Value.Select(q =>
UTType.CreateFromIdentifier(q) ??
UTType.CreateFromMimeType(q) ??
UTType.CreateFromExtension(q) ??
UTTypes.Item)
.ToArray();
var picker = new UIDocumentPickerViewController(
utTypes ?? Array.Empty<UTType>(),
asCopy: true)
{
AllowsMultipleSelection = false
};
TaskCompletionSource<FileResult?> filesTcs = new();
picker.DidPickDocumentAtUrls += (_, e) =>
{
if (e.Urls.Length == 0)
{
filesTcs.TrySetResult(null);
return;
}
var path = e.Urls[0].Path;
if (path == null)
{
filesTcs.TrySetResult(null);
return;
}
filesTcs.TrySetResult(new FileResult(path));
};
picker.WasCancelled += (_, e) =>
{
filesTcs.TrySetResult(null);
};
var controller = Platform.GetCurrentUIViewController();
ArgumentNullException.ThrowIfNull(controller);
await controller.PresentViewControllerAsync(picker, true);
return await filesTcs.Task;
}
}
} You can use it like this #if MACCATALYST
result = await MacFilePicker.PickAsync(pickOptions);
#else
result = await FilePicker.PickAsync(pickOptions);
#endif Not even sure whether this is the best way to do this but it works. I think I modified it from the original MAUI code or something, I don't remember. |
@Khongchai interesting, it looks similar to my code at https://github.com/datvm/LukeMauiFilePicker/blob/master/LukeMauiFilePicker/FilePickerService.MaciOS.cs (but then I probably copied it from MAUI code as well). Are you sure it is working well for Mac? I can copy the differences to my library code then. |
I fixed my problem using @datvm 's nugget thank you so much <3 i will also try your solution @Khongchai it seems to have unique functionalities too |
eee.movWorking 🎉🎉 |
Hi everyone, I've been working on this issue for the past few days and have some insights to share. It appears that the issue with the FilePicker occasionally not working on MacCatalyst is related to the frameworks being used in the MAUI source code. Specifically, I noticed that MAUI is using AppKit, whereas the implementation that successfully returns file selection information is based on UIKit. Here's a brief explanation: MAUI Source Code Usage: The current MAUI implementation relies on AppKit for file picking operations. I believe aligning the MAUI implementation with UIKit, or ensuring proper interoperability between AppKit and UIKit, could potentially resolve this issue. Looking forward to hearing thoughts from others and the maintainers on this. Thank you! |
Just a heads up, this PR #26743 removes a file that was not in use. I think it might have caused some confusion that it references AppKit. It's my feeble attempt to make it easier to fix this issue1. If there is a bug on Mac Catalyst, then this file should be checked out: https://github.com/dotnet/maui/blob/main/src/Essentials/src/FilePicker/FilePicker.ios.cs Footnotes
|
Description
FilePicker returns null as soon as it pops up, 8 out of 10 times.
var result = await FilePicker.Default.PickAsync();
Steps to Reproduce
This should let you choose a file and the name should return in the result above.
But instead it sometime just returns with the result null as soon as the dialog pops up.
If you don't see the bug, try to restart the app, or rebuild it.
Link to public reproduction project repository
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
macOS Ventura 13.3.1 x64
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: