Launching App or App Store from Safari

Launching app OR app store from Safari?

It's not possible to check if app is installed from a web page. You could do it inside an other app by checking if your url scheme can be opened using UIApplication's -canOpenURL: method, but there is no javascript equivalent to this.

However, you can use the following workaround:

<script language="javascript">
function open_appstore() {
window.location='http://itunes.com/';
}

function try_to_open_app() {
setTimeout('open_appstore()', 300);
}
</script>

<a onClick="javascript:try_to_open_app();" href="yourappurl:">App name</a>

This code will set a timeout on the link that will call the open_appstore function if this timeout ends. Since your link is pointed at the app's custom url, Safari will try to open that link and if it can, it will open the app and stop the timer, so AppStore link will not be opened.

If the app link can't be opened, when timer runs out it will display an error popup saying it can't open the page (can't get rid of that), but it will immediately go to AppStore and dismiss that error.


iOS 9 adds a really nice feature that lets your app open a http/s url: Universal Links


In iOS 10 there is a popup saying "Open in [App Name]" when you tap the link and the app is installed. If the user does not tap on "Open" in the given timeout, this solution will use the fallback.
As 300ms is too short to tap anything, this solution always fails on iOS 10.

App store url is opening in safari but it is not opening in chrome.What could be the issue?

Try appending ?mt=8 to your App Store URL like so:

https://apps.apple.com/in/app/gotourney-mobile/id1470734298?mt=8

The parameter mt stands for "media type" and tells the OS what they are dealing with. In this case, media type 8 indicates "Mobile Software Applications".

How Can I Launch The Appstore App Directly from my Application

From iTunes, drag the icon of your app to the desktop, this will give you a link you can use directly (for example, http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284036524&mt=8 launches the AppStore to Crosswords, both on a desktop and an iPhone).

Pop this into an NSURL and call openURL on it.

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)!)
}


Related Topics



Leave a reply



Submit