Forum Xamarin Xamarin.iOS

Open Universal Link from within an app with OpenUrl

DanielKokDanielKok NLUniversity ✭✭
edited January 2017 in Xamarin.iOS

We have an iOS app that is configured to open universal links.
This works fine. When clicking on urls from a browser, notes or email-application, the app is opened and the correct action is taken.

However, these urls also occur within our app as labels that have a TapGestureRecognizer which opens the url as follows:


When the label is tapped, that the url is opened in Safari, which then shows an app banner that allows the users to open it with the app.

I would expect it to open with the same app.

I did find a property on UIApplicationOpenUrlOptions: UniversalLinksOnly. This page definies this as follows:

Use a boolean value set to true (YES) to only open the URL if it is a valid universal link with an application configured to open it. If there is no application configured or the user disabled using it to open the link the completion handler is called with false (NO).

I tried this:

var options = new UIApplicationOpenUrlOptions (); options.UniversalLinksOnly = true; UIApplication.SharedApplication.OpenUrl(new Foundation.NSUrl(url.AbsoluteUri), options, null);

Strangely this blocks the url from opening at all, which would imply that the app is not registered. However opening the links from other apps works without problems, suggesting that the app is registered.

How can we get universal links from within an app to open with the same app?


  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    That is expected behavior. You can't use openURL within your app to call your app. See Universal Links.

    It’s important to understand that if your app uses openURL: to open a universal link to your website, the link always opens in Safari instead of getting redirected to your app. In this scenario, iOS recognizes that the call originates from your app and therefore should not be handled as a universal link.

    So, you'll need to change your gesture handlers to present whatever view your URL would have redirected to.

  • DanielKokDanielKok NLUniversity ✭✭

    Thanks David! So it is intended behaviour.

    We have indeed updated our gesture handlers now, to check for the type of link and perform an action accordingly.

Sign In or Register to comment.