Forum Xamarin.iOS

Cannot override OpenUrl in AppDelegate

ElliotCooleyElliotCooley USMember ✭✭
edited May 1 in Xamarin.iOS

I'm trying to use MSAL in my Xamarin.iOS app, and every tutorial I've found has said to override the OpenUrl method in AppDelegate:

    public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)

        return base.OpenUrl(app, url, options);

However, my AppDelegate class extends UIResponder, and UIResponder has no virtual method OpenUrl to override. Perhaps I have a new version of the template? How can I override OpenUrl?



  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Hi @ElliotCooley , from iOS 13 , you need to detail with openUrl in SceneDelegate.cs file , writing code in OpenUrlContexts method .

    And about accessing Url proerty , you can get it from AnyObject element as follow .

    public void OpenUrlContexts(UIScene scene, NSSet<UIOpenUrlContext> urlContexts) 
        Console.WriteLine("URL property =====" + urlContexts.AnyObject.Url);
        var urlString = urlContexts.AnyObject.Url;
        if( urlString.Equals("wide://"))
            // Run code 
  • ElliotCooleyElliotCooley USMember ✭✭

    Thanks @JuniorJiang.

    urlContexts.AnyObject.Url is of type NSUrl, not string (I need an NSUrl anyways, so that's fine).

    How does that change the condition of the if statement?

    Also, would I use "wide://"? Or replace with my own URL?

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Yeah @ElliotCooley , you're right . urlContexts.AnyObject.Url is a type pf NSUrl.

    If statement depends on Url invoked from where application .

    And you can replace "wide://" with your own URL .

  • ElliotCooleyElliotCooley USMember ✭✭

    I'm not sure if this code is working. When I try and access a web api, instead of the data being returned, html of a page telling me that I need JavaScript to login is returned. Furthermore, when I put a breakpoint in the "OpenUrlContexts" method, it is not hit when I make a call to HttpClient.GetAsync, as I would expect.

Sign In or Register to comment.