Redirect Users to Itunes App Store or Google Play Store

redirect to appstore or google play

The problem is with your script tag and you are missing );

And by the way, did you import jQuery?

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
$(document).ready(function (){
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
}
});
</script>

Redirect to app store or google store after button click

Try this

<button onclick="myFunction()">Click me</button>

<script>
function myFunction() {
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){ window.location.href = 'https://itunes.apple.com/my/app/flipbizz/idexampleapp'; }

if(navigator.userAgent.toLowerCase().indexOf("android") > -1){ window.location.href = 'https://play.google.com/store/apps/details?id=com.exampleapp'; }

//Update #2
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
window.location.href = 'https://www.google.com'; //Desktop Browser
}
}
</script>

Redirects to app store if app is not installed

I'm assuming the link you want to pass by email is an https link. If that's the case, for iOS to be able to redirect it to your app, you'll need to implement universal links. This implementation requires you to register the domain you want to respond to on your entitlements file and add an apple-app-site-association file to your backend. This way Apple can verify the domain you're trying to respond to is really yours.

As a result, when the app gets installed, it can be invoked by your domain links via deeplinking.

Now when there's no installed app able to respond to a specific https domain link, the system will simply open it on a web browser. Consequently, you cannot force iOS to open such links on AppStore directly. What you can do is to check whether the running device is iOS when your website gets accessed and ask the system to show your app on AppStore.

And to request iOS to launch AppStore from a website you can use itms-apps:

const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);

if (iOS) {
// Just replace `https://` with `itms://` on your app's AppStore link.
window.location.href = "itms://itunes.apple.com/us/app/google-maps-transit-food/id585027354?mt=8";
}

// In this example I'm redirecting to Google Maps app page on AppStore.

Note: This is just a simple example used to demonstrate the concept. For a real application, you may want to use a device detection library for browsers, like mobile-detect.js

How to link to apps on the app store

Edited on 2016-02-02

Starting from iOS 6 SKStoreProductViewController class was introduced. You can link an app without leaving your app. Code snippet in Swift 3.x/2.x and Objective-C is here.

A SKStoreProductViewController object presents a store that allows the
user to purchase other media from the App Store. For example, your app
might display the store to allow the user to purchase another app.


From News and Announcement For Apple Developers.

Drive Customers Directly to Your App
on the App Store with iTunes Links
With iTunes links you can provide your
customers with an easy way to access
your apps on the App Store directly
from your website or marketing
campaigns. Creating an iTunes link is
simple and can be made to direct
customers to either a single app, all
your apps, or to a specific app with
your company name specified.

To send customers to a specific
application:
http://itunes.com/apps/appname

To send
customers to a list of apps you have
on the App Store:
http://itunes.com/apps/developername

To send customers to a specific app
with your company name included in the
URL:
http://itunes.com/apps/developername/appname


Additional notes:

You can replace http:// with itms:// or itms-apps:// to avoid redirects.

Please note that itms:// will send the user to the iTunes store and itms-apps:// with send them to the App Store!

For info on naming, see Apple QA1633:

https://developer.apple.com/library/content/qa/qa1633/_index.html.

Edit (as of January 2015):

itunes.com/apps links should be updated to appstore.com/apps. See QA1633 above, which has been updated. A new QA1629 suggests these steps and code for launching the store from an app:

  1. Launch iTunes on your computer.
  2. Search for the item you want to link to.
  3. Right-click or control-click on the item's name in iTunes, then choose "Copy iTunes Store URL" from the pop-up menu.
  4. In your application, create an NSURL object with the copied iTunes URL, then pass this object to UIApplication' s openURL: method to open your item in the App Store.

Sample code:

NSString *iTunesLink = @"itms://itunes.apple.com/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

iOS10+:

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink] options:@{} completionHandler:nil];

Swift 4.2

   let urlStr = "itms-apps://itunes.apple.com/app/apple-store/id375380948?mt=8"
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)

} else {
UIApplication.shared.openURL(URL(string: urlStr)!)
}

Redirect to application if installed, otherwise to App Store

There is no way to check for this.
However, there is a nice workaround.

The idea is basically this:

  1. The first time you open your app, you open up mobile safari from within your app to a predefined URL on your server
  2. On that URL you set up a cookie, like appInstalled to the users mobile safari
  3. You then kick the user back to your app with your registered scheme (same as FB does with SSO)
  4. All your email links point to your website, but on the website you check if the browser is mobile Safari and if the appInstalled cookie exists
  5. If either the browser is not mobile Safari or the cookie is not found, you redirect to the AppStore, or stay in your webpage.
  6. If the conditions of #4 are true, you redirect the user to your app with the registered scheme
  7. If the app has been deleted by the user, so the custom url scheme fails, you have a fail-safe redirect to the appstore

The 2 last steps are explained on this SO post



Related Topics



Leave a reply



Submit