Reputation: 33
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
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.
- application:openURL:sourceApplication:annotation:
where the url
parameter will be the NSURL
that brought the user there.
- 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