1. 設(shè)置URL Types
Paste_Image.png
在容器app的target-->info中如圖設(shè)置一個(gè)URL Types。
設(shè)置的目的:是為了告訴app這個(gè)url是合法的,是用來打開app的url。
2. 給Today添加tap手勢(shì)
Paste_Image.png
實(shí)現(xiàn)點(diǎn)擊手勢(shì):
@IBAction func tap(sender: UITapGestureRecognizer) {
//申明要打開的url
let url = NSURL(string: "alert")
//打開對(duì)應(yīng)的應(yīng)用
extensionContext?.openURL(url!, completionHandler: nil)
}
3. 容器app捕獲url
選擇AppDelegate.swift文件。用下面這個(gè)方法捕獲url。
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if url.scheme == "alert" {
let alertView = UIAlertView(title: "提示", message: "從Today中打開", delegate: nil, cancelButtonTitle: "好的")
alertView.show()
return true
}
return false
}
4. 效果展示
這樣點(diǎn)擊Today之后,就可以啟動(dòng)app啦!
Paste_Image.png