php页面判断是 iphone还是andriod的浏览器&通过 URL types在浏览器打开app(转)
2016-05-26 15:10
627 查看
http://blog.csdn.net/totogo2010/article/details/8925483
[php] view plain copy
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$iphone = (strpos($agent, 'iphone')) ? true : false;
$ipad = (strpos($agent, 'ipad')) ? true : false;
$android = (strpos($agent, 'android')) ? true : false;
if($iphone || $ipad)
{
echo <<<END
<script>window.location.href='itms-apps://itunes.apple.com/cn/app/zhong-guo-tou-zi-zhi-nan/id644856699?mt=8'</script>
END;
}
if($android){
echo "<script>window.location.href='http://www.anzhi.com/dl_app.php?s=803308'</script>";
}
?>
在info.plist里添加 URL types 属性,如下图:
在 AppDelegate里添加代码:
[cpp] view plain copy
- (void)showMsg:(NSString*)msg{
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"tips"
message:[NSString stringWithFormat:@"Schemes url :“%@”",msg]
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if(!url){
return NO;
}
NSString *urlString=[url absoluteString];
[self showMsg:urlString];
return YES;
}
在浏览器里输入:
解决一个二维码不同手机扫描下载时跳转的问题
判断后跳转对应的app下载[php] view plain copy
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$iphone = (strpos($agent, 'iphone')) ? true : false;
$ipad = (strpos($agent, 'ipad')) ? true : false;
$android = (strpos($agent, 'android')) ? true : false;
if($iphone || $ipad)
{
echo <<<END
<script>window.location.href='itms-apps://itunes.apple.com/cn/app/zhong-guo-tou-zi-zhi-nan/id644856699?mt=8'</script>
END;
}
if($android){
echo "<script>window.location.href='http://www.anzhi.com/dl_app.php?s=803308'</script>";
}
?>
类似微信app分享时,直接通过浏览器内核启动app是如何做到的呢?
那在iphone中浏览器启动app是如何做到的呢?一共三步在info.plist里添加 URL types 属性,如下图:
在 AppDelegate里添加代码:
[cpp] view plain copy
- (void)showMsg:(NSString*)msg{
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"tips"
message:[NSString stringWithFormat:@"Schemes url :“%@”",msg]
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
}
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if(!url){
return NO;
}
NSString *urlString=[url absoluteString];
[self showMsg:urlString];
return YES;
}
在浏览器里输入:
相关文章推荐
- iOS开发之遍历Model类的属性并完善使用Runtime给Model类赋值
- cordova 和android studio的第一个项目(常见问题注意!)
- android 倒计时 CountDownTimer
- Android代码分析工具-Method profiling
- ios 拨打电话
- 安卓so动态库加载代理实现,可以实现C层的类反射效果
- iOS UIAppearance使用详解-01没有图片效果
- Toolbar 使用
- iOS 各种传值方式
- [python]使用virtualenvWrapper
- ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结
- android低版本工程(如1.5)放到高版本环境中(如2.2)如何转换
- 转:用迅雷下载Android SDK全系列
- Android根据包名启动应用
- ios 开源的电子书阅读器项目
- opencv-ios开发笔记4 梯度方向直方图hog行人目标图像监测
- android 总结(1)
- 两种方式实现圆形图片
- iOS开发之正则表达式
- iOS开发之类似安卓的Toast短暂提示框