Now that we have URL Schemes up and going, we’ll be adding Universal Links to our three apps.
The Difference Between URL Schemes and Universal Links
URL Schemes are fairly easy for the device to treat “in-house.” There’s no need to look anywhere else. However, Universal Links can point to external resources (across a network connection), which means that they need an external server to provide the endpoints.
Additionally, Universal Links only use one Service: HTTPS (Secure HTTP). Internally, the system can go straight to the app, in the same manner as URL Schemes, but, if the app is not installed, instead of throwing an error and giving up, the system will actually make an HTTP connection across the TCP/IP network (AKA “Teh Internets Tubes”), to a server at the address.
So a Universal Link is actually a custom Host, not a Service, where the URL Scheme is a custom Service.
We Need A Web Server
Because the Service is HTTP, and the link can point to an external server, we need to be able to set up said server. This means declaring a domain name for the Host, and providing an HTTP endpoint at that name resolution. The system may execute an HTTPS connection to that endpoint, as if it were a standard Web server connection.
On that server, we’ll need to upload a custom JSON file, that the system will load, at app install/update time, in the same manner as the URL Scheme. This file will match the Host to the app.
So, when the app is installed, it is queried for Universal Links (which are actually defined in a different manner from URL Schemes) in the app entitlements file. If the system finds an entitlement for Universal Links (called “Associated Domains” – specifically, a service called “applinks”), it actually makes a network call to the Host specified in the entitlement, and fetches that custom JSON file. It then parses that file, and creates a local hash table, like the one for URL Schemes, which matches the app to the Host.
Then, when a service on the system makes a DNS query, it is matched with both the URL Scheme hash table, and the Associated Domains hash table. If either one matches, the app is opened, and the URL is passed to the app, instead of a network lookup.
However, if there is no match, the system doesn’t throw an error, as the Universal Link is a legitimate HTTPS URL. Instead, it simply executes the URL in the standard fashion, as if it were a Web query, and our server is called.
The server doesn’t need to be anything fancy (but it can be, depending on what you want to do). In our case, it can be a very basic server, as we’re just serving simple HTML files. It just needs to be at the specified address, and it needs to be able to provide the custom JSON file, as well as the index.html
file, that we will use.
What We’ll End Up With
Once we have everything in place, executing any of the following URLs on our device will open the app, if it is installed. If it is not installed, you’ll get an error alert, telling you that the URL is bad:
The Standard URL Scheme URLs
- iul1://?off
- iul1://?stop
- iul1://?caution
- iul1://?go
- iul2://?off
- iul2://?stop
- iul2://?caution
- iul2://?go
- iul3://?off
- iul3://?stop
- iul3://?caution
- iul3://?go
But now, we’ll have Universal Link URLs, which will do the same thing:
- https://iul1.littlegreenviper.com?off
- https://iul1.littlegreenviper.com?stop
- https://iul1.littlegreenviper.com?caution
- https://iul1.littlegreenviper.com?go
- https://iul2.littlegreenviper.com?off
- https://iul2.littlegreenviper.com?stop
- https://iul2.littlegreenviper.com?caution
- https://iul2.littlegreenviper.com?go
- https://iul3.littlegreenviper.com?off
- https://iul3.littlegreenviper.com?stop
- https://iul3.littlegreenviper.com?caution
- https://iul3.littlegreenviper.com?go
The difference, this time, is that, if the app is not installed, the URL will now go to a Web page (NOTE: If you are viewing this on a device that has the final versions of the apps installed, the following URLs will open those apps, instead of taking you to the “fallback” Web pages):
- https://iul1.littlegreenviper.com?off
- https://iul1.littlegreenviper.com?stop
- https://iul1.littlegreenviper.com?caution
- https://iul1.littlegreenviper.com?go
- https://iul2.littlegreenviper.com?off
- https://iul2.littlegreenviper.com?stop
- https://iul2.littlegreenviper.com?caution
- https://iul2.littlegreenviper.com?go
- https://iul3.littlegreenviper.com?off
- https://iul3.littlegreenviper.com?stop
- https://iul3.littlegreenviper.com?caution
- https://iul3.littlegreenviper.com?go
Those Web pages are on my server. You’ll need to set up your own server, and your own domains, to see what they give you.
Now that we understand where we’re going, let’s figure out how we’ll get there.