如何生成一个可以跳转app store的二维码跳转appstore

你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。61019人阅读
iOS技术(101)
常常有这样的场景,咱们开发出来的APP需要进行推广,比如在页面顶部来一张大Banner图片,亦或一张二维码。但往往我们都是直接给推广图片加了一个下载链接(App Store中的)。所以咱们来模拟一下用户的操作步骤:
1、用户第一次访问宣传页面
& &a、点击Banner,进入到APP Store中对应的APP下载页
& &b、APP下载页中提示:安装;用户点击安装
& &c、安装完成后,APP下载页中提示:打开;用户继续点击打开
& &d、用户正常使用APP
2、用户第二次访问宣传页面
& &a、点击Banner,进入到APP Store中对应的APP下载页
& &b、APP下载页中提示:打开;用户直接点击打开
& &c、用户正常使用APP
3、用户第三次、第四次、...、第N次访问,操作步骤同2
能看出来,不管是点击Banner还是扫描二维码的方式,对于已经安装过APP的用户来说,这个体验都是非常糟糕的。
更优的体验是:点击Banner(或扫描二维码)后,程序判断当前系统是否已安装App,如果未安装,则自动跳转到App Store下载页;否则直接打开App。
在iOS上,要增加一个APP的大Banner,其实只需要在&head&标签内增加一个&meta&标签即可,格式如:
&meta name='apple-itunes-app' content='app-id=你的APP-ID'&
比如加一个百度贴吧的Native APP大Banner,用下面这串儿代码:
&meta name='apple-itunes-app' content='app-id='&
而对于点击链接后,能否直接打开,可以通过下面的代码来实现。前提条件:你得知道你的APP对应的打开协议,如贴吧APP,协议为:com.baidu.tieba:// ,微信的:weixin:// ,and so on。。。
&!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --&
&a href=&/cn/app/id& id=&openApp&&贴吧客户端&/a&
&script type=&text/javascript&&
document.getElementById('openApp').onclick = function(e){
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
// 否则打开a标签的href链接
var ifr = document.createElement('iframe');
ifr.src = 'com.baidu.tieba://';
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.setTimeout(function(){
document.body.removeChild(ifr);
当然,如果你是设计成一张二维码,可以用下面这段代码:
&!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --&
&a href=&/cn/app/id& id=&openApp& style=&display: none&&贴吧客户端&/a&
&script type=&text/javascript&&
document.getElementById('openApp').onclick = function(e){
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
// 否则打开a标签的href链接
var ifr = document.createElement('iframe');
ifr.src = 'com.baidu.tieba://';
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.setTimeout(function(){
document.body.removeChild(ifr);
document.getElementById('openApp').click();
要使用哪一种,就取决与你的实际场景了!
我们在浏览网页的时候,你会看到一个网页下面漂浮着一个提示框“打开APP”或者“下载APP的字样”,如果你的手机已经安装过这个APP,那么网页会提示“打开APP”,如果没有安装,那就会提示“下载APP的字样” &这个从技术角度是如何去实现的呢?下面我给大家分享这块技术,去年公司给国际动漫节做项目的时候,客户就提到这个需求,在点击网页企业的时候 那么直接打开APP(如果已经安装了) 如果没有安装过,直接打开APP页面
下面我把这块的源码分享一下
(navigator.userAgent.match(/android/i)) {
ifrSrc =&'&type=0&id=${com.id}&phone_num=${com.phone_num}';
ifr = document.createElement('iframe');
&&&&&ifr.src
&&&&&ifr.style.display
&&&&&ifr.onload
= function() {
&&&&&isInstalled
&&&&&alert(isInstalled);
&&&&&document.getElementById('openApp0').click();};
&&&&&ifr.onerror
= function() {
&&&&&&&&&isInstalled
&&&&&&&&&alert(isInstalled);
&&&&&document.body.appendChild(ifr);
&&&&&setTimeout(function()
&&&&&&&&&document.body.removeChild(ifr);
&&&&&},1000);
(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) &{
&&&&&&&&&var
&&&&&&&&&var
ifrSrc =&'${com.short_name}&comID=${com.id}&comPhoneNum=${com.phone_num}&type=0';var
ifr = document.createElement('iframe');
&&&&&&&&&ifr.src
&&&&&&&&&ifr.style.display
&&&&&&&&&ifr.onload
= function() {
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&isInstalled
&&&&&&&&&&&&&&alert(isInstalled);
&&&&&&&&&&&&&&document.getElementById('openApp1').click();};
&&&&&&&&&ifr.onerror
= function() {
&&&&&&&&&&&&&&
&&&&&&&&&&&&&&isInstalled
&&&&&&&&&&&&&&alert(isInstalled);
&&&&&&&&&}
&&&&&&&&&document.body.appendChild(ifr);
&&&&&&&&&setTimeout(function()
&&&&&&&&&&&&&&document.body.removeChild(ifr);
&&&&&&&&&},1000);
大家在做的过程中需要注意两个问题:
1、接口地址一定要写对,大家可以查一下schema协议,通过这个协议调用的
2、在做用安卓的时候 &如果用微信扫一扫或者QQ浏览器扫码功能的时候
使用上面的协议会存在问题的就是必须用APK上架到腾讯应用市场上去
源码下载地址:http://download.csdn.net/detail/wangliang5049
转载请注明:&>>&
http://www.androidchina.net/2435.html
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:889985次
积分:7255
积分:7255
排名:第2885名
原创:63篇
转载:138篇
评论:103条
(2)(1)(2)(1)(1)(2)(1)(4)(6)(9)(2)(8)(9)(8)(8)(7)(2)(5)(4)(7)(10)(5)(6)(3)(3)(4)(10)(3)(1)(4)(5)(8)(14)(9)(10)(3)(1)(1)(1)(3)(2)(4)(1)(2)跳转AppStore的两种方法,应用内和直接跳转 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 9时,
iOS&&跳转AppStore的两种方法,应用内和直接跳转
代码片段(1)
1.&[代码]iOS
跳转AppStore的两种方法,应用内和直接跳转&&&&
#import "ViewController.h"
#import &StoreKit/StoreKit.h&
@interface ViewController ()&SKStoreProductViewControllerDelegate&
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//第一种方法
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"直接跳转" forState:UIControlStateNormal];
btn.tag = 1;
[btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
//第二中方法
应用内跳转
UIButton *btnT = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];
btnT.backgroundColor = [UIColor purpleColor];
btnT.tag = 2;
[btnT setTitle:@"应用内跳转" forState:UIControlStateNormal];
[btnT addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[self.view addSubview:btnT];
- (void)btn:(UIButton *)btn{
if (btn.tag == 1) {
//第一种方法
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps:///app/id"]];
//第二中方法
应用内跳转
//1:导入StoreKit.framework,控制器里面添加框架#import &StoreKit/StoreKit.h&
//2:实现代理SKStoreProductViewControllerDelegate
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
storeProductViewContorller.delegate =
ViewController *viewc = [[ViewController alloc]init];
__weak typeof(viewc) weakViewController =
//加载一个新的视图展示
[storeProductViewContorller loadProductWithParameters:
@{SKStoreProductParameterITunesItemIdentifier : @""} completionBlock:^(BOOL result, NSError *error) {
if(error){
NSLog(@"错误%@",error);
//AS应用界面
[self presentViewController:storeProductViewContorller animated:YES completion:nil];
#pragma mark - 评分取消按钮监听
//取消按钮监听
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:nil];
开源中国-程序员在线工具:
相关的代码(545)
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
[Objective-C]
我刚试了一下,为什么跳转回调没有走。。。而且你的button位置还设置的一样,第18行的btn应该改为btnT
2楼:韩万杰 发表于
谢谢指出错误 &都改过来了 &
开源从代码分享开始
韩万杰的其它代码你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。}

我要回帖

更多关于 二维码网址跳转生成器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信