如何使用 url 打开 ios 应用程序?
How to open ios app using url?
我想使用 URL 方案打开我的 ios 应用程序。我可以使用它打开应用程序。
但我想如果未安装应用程序,则应打开应用程序商店,用户可以在其中下载应用程序。
这可能吗?我该怎么做?
编辑
逐步解释问题:
- 我的收件箱中有一封邮件 url。
- 然后我点击URL
一世。如果应用程序安装在 phone,应用程序将启动。
二.否则将打开应用商店下载应用。
感谢
如果您的应用没有安装在设备上,您可以使用以下代码行打开应用商店:
NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
试试下面的代码:
if([[UIApplication sharedApplication] canOpenURL:url]){
// Means your app is installed, and it can be open
[[UIApplication sharedApplication] openURL:url];
}
else{
//Your app is not installed so, Open app store with your apps iTunes Url
NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
}
在 iOS 5 之后,您还可以使用 https://
来避免重定向。
编辑:
如果安装了 link 从 url 打开应用:Universal links 从 Url 打开应用。
您所描述的称为延迟深度链接(Deep Linking
指的是使用 link 打开您的应用程序,甚至直接指向特定内容,并且 Deferred
意味着即使没有先安装该应用程序,它也能正常工作。
不幸的是,在 iOS 或 Android 上还没有本地方法来完成此操作。 URL 方案不起作用,因为如果未安装该应用程序,它们总是 失败。 Apple 在 iOS 9 中的新 Universal Links 更接近,但您仍然需要处理将用户从您的网站重定向到 App Store
像Branch.io (full disclosure: they're so awesome I work with them) can handle all of this for you though. Here's the docs page covering exactly how to create email links like you described: https://dev.branch.io/features/email-campaigns/overview/
这样的免费服务
我通过我的服务器端代码处理了它:
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("com.myapp://");
setTimeout(function() {
if (!document.webkitHidden) {
location.replace("https://itunes.apple.com/app/xxxxxxxx");
}
}, 25);}
else if ((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/Android/i))) {
location.replace("https://play.google.com/store/apps/details?id=packagename&hl=en");}
else {
location.replace("http://www.example.com");}
我将其放入我的 www.mysite.com/download 页面并通过活动分享此 url。
我想使用 URL 方案打开我的 ios 应用程序。我可以使用它打开应用程序。 但我想如果未安装应用程序,则应打开应用程序商店,用户可以在其中下载应用程序。 这可能吗?我该怎么做?
编辑 逐步解释问题:
- 我的收件箱中有一封邮件 url。
- 然后我点击URL 一世。如果应用程序安装在 phone,应用程序将启动。 二.否则将打开应用商店下载应用。
感谢
如果您的应用没有安装在设备上,您可以使用以下代码行打开应用商店:
NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
试试下面的代码:
if([[UIApplication sharedApplication] canOpenURL:url]){
// Means your app is installed, and it can be open
[[UIApplication sharedApplication] openURL:url];
}
else{
//Your app is not installed so, Open app store with your apps iTunes Url
NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
}
在 iOS 5 之后,您还可以使用 https://
来避免重定向。
编辑:
如果安装了 link 从 url 打开应用:Universal links 从 Url 打开应用。
您所描述的称为延迟深度链接(Deep Linking
指的是使用 link 打开您的应用程序,甚至直接指向特定内容,并且 Deferred
意味着即使没有先安装该应用程序,它也能正常工作。
不幸的是,在 iOS 或 Android 上还没有本地方法来完成此操作。 URL 方案不起作用,因为如果未安装该应用程序,它们总是 失败。 Apple 在 iOS 9 中的新 Universal Links 更接近,但您仍然需要处理将用户从您的网站重定向到 App Store
像Branch.io (full disclosure: they're so awesome I work with them) can handle all of this for you though. Here's the docs page covering exactly how to create email links like you described: https://dev.branch.io/features/email-campaigns/overview/
这样的免费服务我通过我的服务器端代码处理了它:
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("com.myapp://");
setTimeout(function() {
if (!document.webkitHidden) {
location.replace("https://itunes.apple.com/app/xxxxxxxx");
}
}, 25);}
else if ((navigator.userAgent.match(/android/i)) || (navigator.userAgent.match(/Android/i))) {
location.replace("https://play.google.com/store/apps/details?id=packagename&hl=en");}
else {
location.replace("http://www.example.com");}
我将其放入我的 www.mysite.com/download 页面并通过活动分享此 url。