I have a .net maui app that I am trying to get running on MacOS (Catalyst).
When using the example provided in the documentation a "share" dialog open up instead of the PDF file and the default viewer.
It does the same thing when using the exact code from the docs:
string popoverTitle = "Read text file";
string name = "File.txt";
string file = System.IO.Path.Combine(FileSystem.CacheDirectory, name);
System.IO.File.WriteAllText(file, "Hello World");
await Launcher.Default.OpenAsync(new OpenFileRequest(popoverTitle, new ReadOnlyFile(file)));
I associated pdf files with Chrome, and they display fine when launced from Finder.
Any help or work-arounds would be greatly appreciated!
This is standard Catalyst behaviour - Catalyst apps use iOS API, and that API opens the PDF via share.
You can look at the MAUI source to see what exactly the launcher code is doing:
The iOS Launcher code (used in MAUI / MacCatalyst) calls UIApplication.SharedApplication.OpenUrlAsync:
Task<bool> PlatformOpenAsync(NSUrl nativeUrl) =>
UIApplication.SharedApplication.OpenUrlAsync(nativeUrl, new UIApplicationOpenUrlOptions());
The MacOS Launcher code (used in a .Net for MacOS app, but not in a MAUI / MacCatalyst app) calls NSWorkspace.SharedWorkspace.OpenFile:
Task<bool> PlatformOpenAsync(OpenFileRequest request) =>
Task.FromResult(NSWorkspace.SharedWorkspace.OpenFile(request.File.FullPath));
The NSWorkspace version is not available to MacCatalyst apps, so you can't readily bypass the MAUI launcher code to call it.
To get the MacOS behaviour you'll need to launch from a MacOS context. With a bit of trickiness, you can bridge to a MacOS context from your MacCatalyst app and call the MacOS API from there. To do so, include a MacOS bundle in with your Maui Catalyst project and use it to call the MacOS API (Catalyst app -> MacOS bridge component -> MacOS API).
Is it possible to use full screen in Mac Catalyst? walks through the pieces and shows how to NSApplication from a MacCatalyst app. The concepts will be the same to call NSWorkspace from .Net Catalyst app.