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

Thomas Fischer 5 Reputation points

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.

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

    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 =>
                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))
    1 person found this answer helpful.