extension ViewController {
@IBAction func jumpToXinWen(sender: AnyObject) {
openURL("xinWen://")
}
private func openURL (urlString : String) {
let url = NSURL(string: urlString)!
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
}
}
// MARK: - 跳转微信朋友圈
@IBAction func jumpToWeChatTimeLine(sender: AnyObject) {
openURL("WeChat://TimeLine?xinWen")
}
// MARK: - 跳转微信好友
@IBAction func jumpToWeChatSession(sender: AnyObject) {
openURL("WeChat://Session?xinWen")
}
private func openURL (urlString : String) {
let url = NSURL(string: urlString)!
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
extension AppDelegate {
//监听当前程序被其他程序通过什么样的Url打开
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
//根据url跳转对应页面
//1.url转化成字符串
let urlString = url.absoluteString
//2.获取首页控制器
let rootVc = application.keyWindow?.rootViewController
let mainVc = rootVc?.childViewControllers[0] as! ViewController
//将url传递给mianVc
mainVc.urlString = urlString
//3.根据字符串内容完成对应跳转
if urlString.containsString("Session") {//跳转好友
mainVc.performSegueWithIdentifier("Session", sender: nil)
}else if urlString.containsString("TimeLine") {//跳转朋友圈
mainVc.performSegueWithIdentifier("TimeLine", sender: nil)
}
return true
}
}
//切换界面,需要来到该方法.能够拿到切换前后的控制器
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Session" {
let sessionVc = segue.destinationViewController as! SessionViewController
//传递数据
sessionVc.urlString = urlString
}
}
}
class SessionViewController: UIViewController {
//接收数据
var urlString = ""
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "退回跳前应用", style: .Plain, target: self, action: #selector(backToStartApp))
}
}
extension SessionViewController {
func backToStartApp() {
//分割Url,获取跳转前的程序的scheme
let scheme = urlString.componentsSeparatedByString("?")[1]
print(scheme)
//拼接字符串
let backString = "\(scheme)://"
//打开url
openURL(backString)
}
private func openURL (urlString : String) {
let url = NSURL(string: urlString)!
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有