Dr. Mr. Uncle
Dr. Mr. Uncle

Reputation: 604

How can you ignore a universal link if a certain condition is not met?

We currently support wildcarding for Universal Links. So my applinks looks like: applinks:*.company.com.

Let's say I want to only handle a link if it is https://company.com/?query1=abc

Let's say I instead tap on a link that is https://company.com/?query1=123

Since the condition is not met, I want to ignore this link and prevent my iOS App from responding to it. Is this possible?

I thought I'd just be able to return false in continue:restorationHandler but that does not prevent the iOS App from opening.

Upvotes: 1

Views: 1038

Answers (1)

Paulw11
Paulw11

Reputation: 114974

Returning false from application(_:continue:restorationHandler:) doesn't result in the URL being passed back to Safari (as you have discovered). The documentation states:

If you don't implement this method or if your implementation returns false, iOS tries to create a document for your app to open using a URL

So returning false just results in iOS trying to launch your app in a different way.

What you can do is call open(_:options:completionHandler:) and pass the URL you received. The URL will then be opened in Safari; iOS won't pass your app a universal link that your app opens itself because that could create an infinite loop.

Upvotes: 2

Related Questions