How do I get FilePicker to return a non-null result on MacCatalyst?
Maui Workload 9.0.14/9.0.100
SDK 9.0.200
XCode 16.3 (16e140)
Mac OS Sequoia 15.3.2
Visual Studio Code 1.98.2 (Universal)
I am developing a MAUI App that needs to run on Windows, MacOS and iOS (iPad only). I am trying to get FilePicker.Default.PickAsync() to return a non-null result on a Mac. It returns a non-null result on Windows and using the iPad simulator. On MacCatalyst, FilePicker.Default.PickAsync() displays the correct file selection dialog. I navigate to my Downloads folder, select the file I want to use, and click [Open]. The result from FilePicker.Default.PickAsync() is always null.
Code snippet that works on Windows and iOS, but returns null on MacOS (it's inside a try/catch block):
PickOptions options = new PickOptions();
options.PickerTitle = "Select a SmartRun 4 run file";
var runFileType =
new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "public.comma-separated-values-text" } },
{ DevicePlatform.WinUI, new[] { ".csv" } },
{ DevicePlatform.MacCatalyst, new[] { "public.comma-separated-values-text" } }
});
options.FileTypes = runFileType;
FileResult? result = await FilePicker.Default.PickAsync(options);
if (result != null)
{
// I get here on Windows and iOS. I never get here (no exceptions) on MacOS
// as result is always null.
My MacCatalyst Entitlements.plist file contains the following entries as noted on the .NET MAUI FilePicker information page:
<key>com.apple.security.assets.movies.read-only</key>
<true/>
<key>com.apple.security.assets.music.read-only</key>
<true/>
<key>com.apple.security.assets.pictures.read-only</key>
<true/>
<key>com.apple.security.files.downloads.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
I've also added the following entries to Entitlements.plist in a desperate attempt to get a non-null result:
<key>com.apple.security.files.downloads.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
I have the following entries in both the iOS and MacCatalyst Info.plist files. Apple's documentation indicates they should be present:
<key>NSDownloadsFolderUsageDescription</key>
<string>The Downloads folder is where your browser saves files.</string>
<key>NSDocumentsFolderUsageDescription</key>
<string>The Documents folder is where you might copy files from some elsewhere.</string>
If I don't use a FilePicker and just pass the full file path (in my Downloads folder) to File.ReadLines(), the program successfully reads the file. I therefore know the file can be accessed within the program. I just need FilePicker to work. What am I missing? Please help.