How to open ios app using url?

社会主义新天地 提交于 2019-11-30 01:42:39

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.

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/

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.

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