Xamarin-macios: UIApplication.OpenURLOptionsKey.sourceApplication

Created on 16 Sep 2019  路  5Comments  路  Source: xamarin/xamarin-macios

I am build a demo with third party login, I meet a problem about "UIApplication.OpenURLOptionsKey.sourceApplication", I can not find the key string in Xamarin.iOS. Can any one help me?

in swift:
image

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let urlKey: String = options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String

        if urlKey == "com.tencent.mqq" {
            return TencentOAuth.handleOpen(url)
        }

        return application(app, open: url, options: options)
    }

And in C#:
image
```C#
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
var urlKey = options[UIApplication.LaunchOptionsUrlKey]?.ToString();

        if (urlKey == "com.tencent.mqq")
        {
            return TencentOAuth.HandleOpenURL(url);
        }
        return base.OpenUrl(app, url, options);
    }

```

support

Most helpful comment

Hello 馃憢

Yeah as @chamons said you want to do this

public override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)
{
        var openOptions = new UIApplicationOpenUrlOptions (options);
        if (openOptions?.SourceApplication == "blah")
                // handle scenario
        return base.OpenUrl(app, url, options);
}

Hope this helps.

All 5 comments

Hi Carl,

Thank you for your feedback!

It is likely that UIKit.UIApplicationOpenUrlOptions is the API you are looking for.

For more information about dictionary wrappers, check out: https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/binding/binding-types-reference#strongly-typed-dictionaries

Hi Carl,

Thank you for your feedback!

It is likely that UIKit.UIApplicationOpenUrlOptions is the API you are looking for.

> For more information about dictionary wrappers, check out: https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/binding/binding-types-reference#strongly-typed-dictionaries

@whitneyschmidt Hello, thanks for your reply, do you mean this class:(I tried, but it didn't work,
But I think I need a static const string here.)
image
image
Maybe this class(below) should be used here, but I don't know why it is internal.
image


Do you know what should I do?

Try creating a new instance with:

public UIApplicationOpenUrlOptions (NSDictionary dictionary)

and then poking 锘匡豢SourceApplication

I thought we exposed those keys as well, but apparently aren't. I'm looking into that.

Hello 馃憢

Yeah as @chamons said you want to do this

public override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)
{
        var openOptions = new UIApplicationOpenUrlOptions (options);
        if (openOptions?.SourceApplication == "blah")
                // handle scenario
        return base.OpenUrl(app, url, options);
}

Hope this helps.

@chamons @dalexsoto Thank you very much! It works well now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ormaa picture ormaa  路  3Comments

cwensley picture cwensley  路  3Comments

chamons picture chamons  路  4Comments

whitneyschmidt picture whitneyschmidt  路  3Comments

Mikilll94 picture Mikilll94  路  4Comments