Xamarin Macintosh Customer URL protocol handle pas

2019-05-28 13:18发布

问题:

I've written a Macintosh app that handles a custom protocol:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>My Cool Handler</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>coolhandler</string>
        </array>
    </dict>
</array>

All well and good. It launches. However, I'm clicking on a link like this:

coolhandler://Iwant/toparse/this

In Windows, the registry entry is simple and this work just fine. When my Windows app launches, the whole url is passed as an argument and I can parse it.

    protected override void OnStartup(StartupEventArgs e)
    {
        _url = !e.Args.Any()?"":e.Args[0];
        //parse the url
    }

Where, in my pList or in the app do I handle this? i.e, how do I pass the url argument to the app?

回答1:

You'll need to do something like this in C# likely:

Accessing command line arguments in Objective-C

Which would look something like:

string[] args = NSProcessInfo.ProcessInfo.Arguments;