Con*_*oob 60 redirect app-store ios
我知道可以通过注册自定义方案(例如so://)直接链接到iOS中的应用程序,也可以通过iTunes链接到appstore中的应用程序.
在许多情况下,理想的流程是提供一个链接,如果安装了应用程序,则重定向到应用程序,如果没有,则提供给商店.这是可能的,如果是的话,怎么样?
为了清楚起见,添加的方案是我在iphone上打开一个电子邮件链接(http),邀请我加入应用程序中的一个组.如果用户在该设备上安装了应用程序,则应该打开,否则http链接应该重定向到iTunes.
Ban*_*eil 54
我认为更简单的答案是使用以下javascript在您的服务器上设置页面:
(function() {
var app = {
launchApp: function() {
window.location.replace("myapp://");
this.timer = setTimeout(this.openWebApp, 1000);
},
openWebApp: function() {
window.location.replace("http://itunesstorelink/");
}
};
app.launchApp();
})();
Run Code Online (Sandbox Code Playgroud)
这基本上会尝试重定向到您的应用并设置超时,以便在应用商店失败时重定向到应用商店.
您甚至可以使代码更加智能,并检查用户代理以查看它们是否是ios用户,Android用户或webuser,然后适当地重定向它们.
Lef*_*ris 26
没有办法检查这个.但是,有一个很好的解决方法.
这个想法基本上是这样的:
最后两个步骤在此SO帖子中进行了解释
q0r*_*ban 14
如果你有一个网页,你用含有网页的电子邮件链接到iframe同src一套为您的应用程序自定义方案,,iOS将自动重定向到在App该位置.如果未安装该应用程序,则不会发生任何事情.这允许您深入链接到应用程序(如果已安装),或者如果未安装则重定向到App Store.
例如,如果您安装了Twitter应用程序,并导航到包含以下标记的网页,您将立即转到该应用程序.如果您没有安装Twitter应用程序,您会看到文本"未安装Twitter应用程序".
<!DOCTYPE html>
<html>
<head>
<title>iOS Automatic Deep Linking</title>
</head>
<body>
<iframe src="twitter://" width="0" height="0"></iframe>
<p>The Twitter App is not installed</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是一个更全面的示例,如果未安装App,则重定向到App Store:
<!DOCTYPE html>
<html>
<head>
<title>iOS Automatic Deep Linking</title>
<script src='//code.jquery.com/jquery-1.11.2.min.js'></script>
<script src='//mobileesp.googlecode.com/svn/JavaScript/mdetect.js'></script>
<script>
(function ($, MobileEsp) {
// On document ready, redirect to the App on the App store.
$(function () {
if (typeof MobileEsp.DetectIos !== 'undefined' && MobileEsp.DetectIos()) {
// Add an iframe to twitter://, and then an iframe for the app store
// link. If the first fails to redirect to the Twitter app, the
// second will redirect to the app on the App Store. We use jQuery
// to add this after the document is fully loaded, so if the user
// comes back to the browser, they see the content they expect.
$('body').append('<iframe class="twitter-detect" src="twitter://" />')
.append('<iframe class="twitter-detect" src="itms-apps://itunes.com/apps/twitter" />');
}
});
})(jQuery, MobileEsp);
</script>
<style type="text/css">
.twitter-detect {
display: none;
}
</style>
</head>
<body>
<p>Website content.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
"智能应用程序横幅" - 不确定他们何时出现,但在找到这篇文章寻找相同内容后,智能应用程序横幅,这是后续行动.
智能应用横幅是您希望通过网络体验为您的应用提供的每个页面标题中的单行html元标记:
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
Run Code Online (Sandbox Code Playgroud)
它显示页面顶部的图标和"使用应用程序打开此页面"或路由到App Store.
iPhone上此页面的元数据如下所示(当然是匿名的):
<meta name="apple-itunes-app" content="app-id=605841731, app-argument=lync://confjoin?url=https://meet.rtc.yourcorporatedomain.com/firstName.lastName/conferenceID">
Run Code Online (Sandbox Code Playgroud)
Apple 开发人员文档 - 使用智能应用程序横幅推广应用程序
是的,非常容易.这需要您要打开的应用程序在plist中声明一个url方案:
//if you can open your app
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yourapp://"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourapp://"]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ituneappstorelink"]];
}
Run Code Online (Sandbox Code Playgroud)
只需几个简单的步骤即可实现此操作
步骤1
转到 -> 项目(选择目标) -> 信息 -> URL 类型
像这样在 Xcode 中创建 URL 方案
这里的URLScheme是myApp(最好所有字符都是小写)。
第2步
如果您计划从 URL 接收参数/查询字符串,请设置委托
这是代码:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
NSLog(@"APP : simple action %@",url.scheme);
if ([url.scheme hasPrefix:@"myapp"]) {
NSLog(@"APP inside simple %@",url.absoluteString);
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url
resolvingAgainstBaseURL:NO];
NSArray *queryItems = urlComponents.queryItems;
NSString * abc = [self valueForKey:@"abc"
fromQueryItems:queryItems];
NSString * xyz = [self valueForKey:@"xyz"
fromQueryItems:queryItems];
NSLog(@"Sid up = %@", abc);
NSLog(@"PID up = %@", xyz);
// you can do anything you want to do here
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
Xcode 端工作结束。
步骤3
在这里引用 @BananaNeil 代码,因为我不是前端人员
(function() {
var app = {
launchApp: function() {
window.location.replace("myApp://share?abc=12&xyz=123");
this.timer = setTimeout(this.openWebApp, 1000);
},
openWebApp: function() {
window.location.replace("http://itunesstorelink/");
}
};
app.launchApp();
})();
Run Code Online (Sandbox Code Playgroud)
希望对大家有所帮助
| 归档时间: |
|
| 查看次数: |
64795 次 |
| 最近记录: |