深层链接基本上只是设置应用程序的 url,以便其他应用程序可以使用信息启动它。如果您进行设置以便您的应用程序对某些 URL 做出反应,则可以启动应用程序的某些部分。因此,您必须做一些事情。对于此示例,我将使用两个应用程序。如果您尝试与现有应用程序集成,您只需找出它们的 url 方案是什么。因此,在本示例中,我将使用“消息”作为一个应用程序,使用“时间表”作为另一个应用程序。
首先:在“消息”应用程序中,我们需要设置计划应用程序要调用的方案。
So open up your first app we need to add schemes so other apps can open it. Go to your info.plist
click the little + and type URL types
hit the triangle to expand and hit the + type URL Schemes
and within that one add an item and put your apps name in it. Also add URL identifier
along with $(PRODUCT_BUNDLE_IDENTIFIER)
as the value. `
然后我们只需要添加我们可以打开的应用程序,再次点击顶层 + 并添加LSApplicationQueriesSchemes
这会将应用程序列入白名单,以便我们可以评估天气是否将它们安装在设备上。
Now we can jump over to the other app and create a way to call this. For this example lets make it happen when we press a button.
IBAction launchMessagesApp() {
let url = NSURL(string: "Messages://") where UIApplication.sharedApplication().canOpenURL(url) {
self.launchAppWithURL(url, name: "Messages")
}
The canOpenURL(url)
检查应用程序是否在设备上。如果您愿意,您可以将应用程序商店启动到您的应用程序(如果返回错误)。然后launchAppWithURL
实际上启动了它。这是基本设置,您可能还希望发生多种情况,因此您可能有多个 url 方案来启动同一个应用程序,但将其带到应用程序的不同部分。在函数中应用程序的应用程序委托中
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
print(url)
//Any customizations for the app here
}
你可以做任何你能想象到的事情。