深层链接URI如何在iOS上运行?

use*_*017 2 deep-linking ios

travelbrand://酒店/ 123

这是深层链接URI的一个例子; 在哪里告诉我的应用程序"酒店"这个词是指包含酒店的视图控制器?

Dim*_*ima 7

当有人点击链接并且操作系统将其路由到您的应用程序时,您的两种方法之一UIApplicationDelegate将被调用.

  1. 如果应用程序已在运行,那么方法将是

- application:openURL:sourceApplication:annotation:

其中url参数将是NSURL吸引用户那里.

  1. 如果应用程序是冷启动,那么方法将是

- application:didFinishLaunchingWithOptions:

并且该launchOptions参数将包含一个调用的键UIApplicationLaunchOptionsURLKey,其值将NSURL是用于启动应用程序的值.

在任何一种情况下,你最终得到一个NSURL你可以手动解析,通过获取absoluteString和执行字符串操作,或使用类似的东西NSURLComponents.

一个NSURLComponents为你的URL可能看起来像解决方案:

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
NSString *scheme = components.scheme; // travelbrand
NSString *host = components.host; // hotel
NSString *path = components.path; // /123
Run Code Online (Sandbox Code Playgroud)