user10017
user10017

Reputation: 33

How does deep link URI works on iOS?

travelbrand://hotel/123

this is an example of deep link URI; where to tell my app that the word "hotel" means the view controler which contains the hotels?

Upvotes: 2

Views: 397

Answers (1)

Dima
Dima

Reputation: 23624

When someone taps a link and the OS routes it into your app, one of two methods in your UIApplicationDelegate will be called.

  1. If the app is already running, then the method will be

- application:openURL:sourceApplication:annotation:

where the url parameter will be the NSURL that brought the user there.

  1. If the app is cold started, then the method will be

- application:didFinishLaunchingWithOptions:

and the launchOptions parameter will contain a key called UIApplicationLaunchOptionsURLKey for which the value will be the NSURL that was used to launch the app.

In either case, you end up with an NSURL which you can parse either manually by getting the absoluteString and doing string manipulation on it, or by using something like NSURLComponents.

a NSURLComponents solution for your URL might look like:

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
NSString *scheme = components.scheme; // travelbrand
NSString *host = components.host; // hotel
NSString *path = components.path; // /123

Upvotes: 7

Related Questions