ios 如何使用url打开ios应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35866742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open ios app using url?
提问by Vivek Sinha
I want to open my ios app using URL schemes. I am able to open app using this. But I want if app is not installed then app store should be opened where user can download app. Is this possible? How can I do that?
我想使用 URL 方案打开我的 ios 应用程序。我可以使用它打开应用程序。但我想如果没有安装应用程序,那么应该打开应用程序商店,用户可以在那里下载应用程序。这可能吗?我怎样才能做到这一点?
EDITExplaining question step wise:
编辑逐步解释问题:
- I have a mail in my inbox with a url.
- I click on URL then i. If app is installed in phone, app will launch. ii. Otherwise app store will be opened to download app.
- 我的收件箱中有一封带有网址的邮件。
- 我点击 URL 然后我。如果手机中安装了应用程序,应用程序将启动。ii. 否则将打开应用商店下载应用。
Thank
谢谢
采纳答案by Vivek Sinha
I handled it via my server side code:
我通过我的服务器端代码处理它:
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");}
I put this in my www.mysite.com/download page & share this url via campaigns.
我把它放在我的 www.mysite.com/download 页面并通过活动分享这个 url。
回答by Alex Bauer
What you're describing is called Deferred Deep Linking (Deep Linking
refers to using a link to open your app, even directly to a specific piece of content, and Deferred
means that it works even if the app isn't installed first).
您所描述的称为延迟深度链接(Deep Linking
指的是使用链接打开您的应用程序,甚至直接打开特定内容,Deferred
这意味着即使未先安装该应用程序也能正常工作)。
Unfortunately there's no native way to accomplish this yet on either iOS or Android. URL schemes don't work, because they alwaysfail if the app isn't installed. Apple's new Universal Linksin iOS 9 get closer, but you'd still have to handle redirecting the user from your website to the App Store
不幸的是,目前还没有在 iOS 或 Android 上实现这一点的原生方法。URL 方案不起作用,因为如果未安装应用程序,它们总是会失败。苹果在 iOS 9 中的新通用链接越来越近了,但你仍然需要处理将用户从你的网站重定向到 App Store
A free service like 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/
不过,像Branch.io这样的免费服务(完全披露:他们太棒了,我和他们一起工作)可以为您处理所有这些。这是文档页面,涵盖了如何像您描述的那样创建电子邮件链接:https: //dev.branch.io/features/email-campaigns/overview/
回答by Ronak Chaniyara
If your App is not installed in device then, you can open app store using below lines of code:
如果您的应用程序未安装在设备中,您可以使用以下代码行打开应用程序商店:
NSString *iTunesUrlofApp = @"itms://itunes.apple.com/us/app/apple-store/...";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesUrlofApp]];
Try below code:
试试下面的代码:
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]];
}
After iOS 5 you can also use https://
to avoid redirections.
在 iOS 5 之后,您还可以使用https://
来避免重定向。
Edit:
编辑:
Check the link to open app from url if installed: Universal linksto open app from Url.
如果已安装,请检查从 url 打开应用程序的链接:Universal linksto open app from Url。