Custom URL scheme for native application or website

I want to develop a URL that, if my application is installed, will be processed through the application. If it is not an iPhone or our application is not installed, I want to redirect to a web url.

Basically, just like the application store URL works.

+4
source share
3 answers

Unfortunately, custom URL handlers on iOS do not work.

You can define custom URL patterns that your application will open, but you cannot make your application the designated handler for specific domain names so that opening this domain in Safari will automatically launch your application.

To be clear, the scheme is a bit before the domain name, for example http:, so you can make your application a handler for the URLs starting myapp: for example. Obviously, no real URLs start with myapp:, except for those that you specifically designed for your application - that’s the whole point.

Unfortunately, these URLs will only work with your application, they cannot be opened in Safari if your application is not installed. iTunes, Google Maps, Youtube, etc. it all works on the iPhone, because Apple hard coded them as special cases, but they do not make this mechanism available for third-party applications.

To register a custom schema for your application, follow this guide: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

Instead, you can create a regular web page that uses javascript to discover the device’s user agent, and if it redirects iPhone to the user’s application’s schema automatically using document.location = 'myapp: ...'. I'm not sure what will happen if you try to redirect to a custom URL scheme if the application is not installed. It may not do anything that would be ideal for you, or it may cause an error or go to a blank page, in which case you better not see a message like "click here to launch the application, or click here to download it from app store, "which seems to make most sites.

+7
source

You should create a regular website with a regular URL and then redirect to a URL like yourapp: // dosomething. Webbrowser, like Safari, should ignore the URL if there is no application (your application) with the "yourapp: //" protocol processing.

Redirection is, for example, possible with setting the header with redirection in php:

<?php header('Location: yourapp://dosomething'); ?> 

Possible for other Server Script languages. You should also include the distinction between "MobileSafari" and other browsers and just go there.

 <?php /* detect Mobile Safari */ $browserAsString = $_SERVER['HTTP_USER_AGENT']; if (strstr($browserAsString, " AppleWebKit/") && strstr($browserAsString, " Mobile/")) { header('Location: yourapp://dosomething'); } ?> 
+6
source

You can use canOpenURL : the application verification method can open the given resource URL or not. Learn more about Apple Doc .

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1387149/


All Articles