在文件中创建了 URL 类型info.plist
,其 URL 方案为http
. 创建了NSUserActivity
类型。UIWebView
在“ViewController”类中创建了权利。在AppDelegate
我实现以下代码的方法中:
func application (application: UIApplication,willContinueUserActivityWithType userActivityType: String) -> Bool {
let sharedUserActivityType = "com.test.testApp"
if (userActivityType == sharedUserActivityType) {
return true
}
return false
}
@available(iOS 8.0, *)
internal override func restoreUserActivityState(activity: NSUserActivity) {
//don't forget to call super!
if #available(iOS 8.0, *) {
super.restoreUserActivityState(activity)
let userInfo = activity.userInfo
} else {
// Fallback on earlier versions
}
}
func application(application: UIApplication, continueUserActivity
userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) ->
Void) -> Bool {
if userActivity == "com.test.testApp.view"
{
let mainListing = ViewController()
restorationHandler([mainListing])
}
if let window = self.window
{
window.rootViewController?.restoreUserActivityState(userActivity)
}
return true
}
func application(app: UIApplication, openURL url: NSURL, options:
[String : AnyObject]) -> Bool {
return true
}
创建了名为 apple-app-site-association 的 json 文件
{ "applinks": { "apps":[], "details": { "teamId.com.test.testApp": { "paths":["*"] } } } }
我签署了 apple-app-site-association 文件,但由于我使用的是 iOS9,因此无需签署。
我实现了方法 application:continueActivity 并返回 YES。
- 但是我的链接没有在应用程序中打开,而是在 Safari 中打开。