How can I handle the starting of a .Net MAUI App by MAC-Finder with a document? (open with..)

Thomas Fischer 5 Reputation points
2023-05-05T08:55:48.4233333+00:00

In Mac-OS I can start a MAUI-App in Finder by selecting a file - and using „Open with“. If the App supports this document-type - how do I get the Filename/path to open in the implementation of the MAUI-App?

It seems not be delivered in the CommandLine-Args of the App.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,046 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Thomas Fischer 5 Reputation points
    2023-05-08T15:07:17.01+00:00

    Correct - the App shall be started by a selection of a file in Finder with :

    (Select File) -> Right Mouse Click -> Open With -> MyApp....

    My question was, how I can handle that in my .Net MAUI-App.

    I meanwhile found the solution:

    In MauiProgram.cs, I have to configure Lifecycle-Events:

            builder.ConfigureLifecycleEvents(events =>
    		{
    #if IOS || MACCATALYST
                events.AddiOS(ios => ios
    						.OnActivated       ((app)          => App.OnActivated         ())
    						.OnResignActivation((app)          => App.OnResignActivation  ())
    						.DidEnterBackground((app)          => App.DidEnterBackground  ())
    						.WillTerminate     ((app)          => App.WillTerminate       ())
    						.FinishedLaunching ((app,par)      => App.FinishedLaunching   (par))
    						.OpenUrl           ((app,url,opts) => App.OpenMidiFileWithUrl (url, opts))
    				        );
    #endif
    
            });
    
    1 person found this answer helpful.