热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Swift-打开第三方应用,并传递参数(附常用App的URLScheme)

一,使用样例常用的第三方应用都定义了不同的URLScheme,我们通过UIApplication.sharedApplication().openURL()方法打开相应的链接,即可跳转到对应的
一,使用样例常用的第三方应用都定义了不同的 URL Scheme,我们通过 UIApplication.sharedApplication().openURL() 方法打开相应的链接,即可跳转到对应的 App 中。

1,打开淘宝下面样例点击按钮后,会自动跳转到淘宝App中。由于我们还传递了一个商品链接参数,那么跳转过来后就会自动打开该商品页面。     原文:Swift - 打开第三方应用,并传递参数(附常用App的URL Scheme)        原文:Swift - 打开第三方应用,并传递参数(附常用App的URL Scheme)
123456789101112131415161718 import UIKit class ViewControllerUIViewController {     override func viewDidLoad() {        super.viewDidLoad()    }         @IBAction func click(sender: AnyObject) {        let urlString = "taobao://item.taobao.com/item.htm?id=22671596473"        let url = NSURL(string: urlString)        UIApplication.sharedApplication().openURL(url!)    }     override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

2,打开百度地图
下面样例点击按钮后,会自动跳转到百度地图App中。由于我们还传递了地址作为参数,那么跳转过来后就会自动定位到该位置。(注意:由于参数中带有中文,我们这里使用 stringByAddingPercentEncodingWithAllowedCharacters 方法对其转义一下。)     原文:Swift - 打开第三方应用,并传递参数(附常用App的URL Scheme)        原文:Swift - 打开第三方应用,并传递参数(附常用App的URL Scheme)
1234567891011121314151617181920 import UIKit class ViewControllerUIViewController {     override func viewDidLoad() {        super.viewDidLoad()    }         @IBAction func click(sender: AnyObject) {        let urlStr = "baidumap://map/geocoder?address=北京市海淀区上地信息路9号奎科科技大厦"        let encodeUrlString = urlStr.stringByAddingPercentEncodingWithAllowedCharacters(            .URLQueryAllowedCharacterSet())!        let url = NSURL(string: encodeUrlString)        UIApplication.sharedApplication().openURL(url!)    }     override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

二,常见应用的URL Scheme
1,系统默认应用
 名称 URL Scheme Bundle identifier
 Safari  http://  
 maps  http://maps.google.com  
 Phone  tel://  
 SMS  sms://  
 Mail  mailto://  
 iBooks  ibooks://  
 App Store  itms-apps://itunes.apple.com  
 Music  music://  
 Videos  videos://  

2,常用第三方软件
 名称 URL Scheme Bundle identifier
 QQ  mqq://  
 微信  weixin://  
 腾讯微博  TencentWeibo://  
 淘宝  taobao://  
 支付宝  alipay://  
 微博  sinaweibo://  
 weico微博  weico://  
 QQ浏览器  mqqbrowser:// com.tencent.mttlite
 uc浏览器  dolphin:// com.dolphin.browser.iphone.chinese
 欧朋浏览器  ohttp:// com.oupeng.mini
 搜狗浏览器  SogouMSE:// com.sogou.SogouExplorerMobile
 百度地图  baidumap:// com.baidu.map
 Chrome  googlechrome://  
 优酷  youku://  
 京东 openapp.jdmoble://  
 人人  renren://  
 美团  imeituan://  
 1号店  wccbyihaodian://  
 我查查  wcc://  
 有道词典  yddictproapp://  
 知乎  zhihu://  
 点评  dianping://  
 微盘  sinavdisk://  
 豆瓣fm  doubanradio://  
 网易公开课  ntesopen://  
 名片全能王  camcard://  
 QQ音乐   qqmusic://  
 腾讯视频  tenvideo://  
 豆瓣电影  doubanmovie://  
 网易云音乐  orpheus://  
 网易新闻  newsapp://  
 网易应用  apper://  
 网易彩票  ntescaipiao://  
 有道云笔记  youdaonote://  
 多看  duokan-reader://  
 全国空气质量指数  dirtybeijing://  
 百度音乐  baidumusic://  
 下厨房   xcfapp://  

原文出自: www.hangge.com   转载请保留原文链接: http://www.hangge.com/blog/cache/detail_1141.html
推荐阅读
author-avatar
mobiledu2502855757
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有