How to open ios app using url?

回眸只為那壹抹淺笑 提交于 2019-11-28 21:12:01

问题


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?

EDIT Explaining question step wise:

  1. I have a mail in my inbox with a url.
  2. 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.

Thank


回答1:


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.




回答2:


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).

Unfortunately there's no native way to accomplish this yet on either iOS or Android. URL schemes don't work, because they always fail if the app isn't installed. Apple's new Universal Links in iOS 9 get closer, but you'd still have to handle redirecting the user from your website to the 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/




回答3:


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.

Edit:

Check the link to open app from url if installed: Universal links to open app from Url.



来源:https://stackoverflow.com/questions/35866742/how-to-open-ios-app-using-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!