Using custom URL schemes

Specifying a custom URLs allow an application to be woken up when a specific URL is selected on a device. For example, the custom URL could be a home URL of the application web page.

Creating the sample stacks

This lesson uses 2 stacks,

1. The "launchee" stack, which is launched by a custom URL

2. The "launcher" stack, which calls the URL causing the first stack to launch.

The "launchee" stack can also be launched by entering the URL in a web browser.

The Launcher Stack

The "launcher" stack consists of 3 buttons which launch various URLs. The custom URL of the "launchee" stack is "webme" and any URL beginning with that string will launch the app. The rest of the URL can contain arguments or extra information that can be used by the "launchee" stack.

The script of the top button is

on mouseUp
    launch url "webme://"
end mouseUp

The other also use the launch url command.

The Launchee Stack

This is the stack that is launched, it has a field to display the the URL that caused it to be launched and a button that uses the mobileGetLaunchURL function to display the URL.

The script of the button is

on mouseUp
    local tURL
    ## This function returns the URL that was used to launch the application.
    put mobileGetLaunchUrl() into tURL
    answer tURL with "Okay"
end mouseUp

The urlWakeUp message

The "launchee" stack also handles the urlWakeUp message. This message is sent to an app when it is launched via a custom URL, it has 1 parameter, wakeUpString, which is the URL that launched the app. The "launchee" stack handles this message in the card script.

on urlWakeUp pURL
    ## This message is received by the app when a custom url is used to launch the app
    put pURL into field "url"
end urlWakeUp

Setting the Custom URL

An app's custom url is specified the the iOS or Android pane of the Standalone Application Settings. In this example the custom URL we want to use is "webme".

Launching the app from the Launcher stack

Deploy both stacks to your simulator or device, open the "launcher" stack and click any of the buttons. The "launchee" stack will open and the URL you selected will be displayed in the field. If you click the "Get Launch URL" button and answer dialog will be shown displaying the URL.

Launching the app from a browser

Once the "launchee" app is on your device you can also launch it from a browser, by going to any URL that starts with the custom URL of the app.

21 Comments

Barry G. Sumpter

Nice!
Is there a way for the launchee to send back a message to the Laucher with data or perhaps a "Successful" or "Unsuccessful" message directly?

Hanson Schmidt-Cornelius

Hi Barry,

I am not aware of a way to implement this directly.

If the Launcher is still running as the main application, after the Launchee was called, then you may want to assume that the launch action was unsuccessful.

Alternatively, you could try this:

Using parameters you send to the Launchee as part of the URL to control its behaviour, it should be possible for the Launchee to launch the Launcher again. This would indicate that the Launchee is accessible and was lunched. In this case the Launcher and the Launchee would have to be registered with individual custom URLs. Don't think this is the most elegant approach though, as the user would see the launches of the applications.

Kind Regards,

Hanson

Barry G. Sumpter

Hi Hanson,

Many thanks for the reply.

I've found the Laucher app is still in the process thead and can't be exited until after the launchee app has been exited.
I think thats an Android rule. Unless there is a special command in LiveCode so the laucher app can reliquish process control to the lauchee app.

I've setup a Path and File name parameter to send to the lauchee app. As to where to save any info I want to communicate between the two.

I've setup a timer in the Laucher app to check 10 times for the existance of that path and file name every 3 seconds.

Certainly not the most eligant approach either but works for me at the moment.

Hanson Schmidt-Cornelius

Hi Barry,

that is a very interesting approach and it saves you launching the launcher stack again. Would not have considered that.

LiveCode does not offer a command to relinquish control.

Kind Regards,

Hanson

Devide colonnel

I got everything ordered ie my piece of hardware and smart phone with an on screen camera
That's proper on my desktop but i want a program that can define
my customized url and launch a few graphics before it manifests its proper domains

Elanor Buchanan

Hi Devide

You can define the Custom URL scheme for your app. The Custom URL can be used to launch your app and you set up the behavior of the app, so if you want to show graphics or a video on startup before the main app is show you can do that.

Kind regards

Elanor

Graham Samuel

This is great stuff, and I see it will work well for two LC-originated apps.

I want my app to be able to launch an existing app, not one coded by me, and with no access to the source code. Is there a way to know what its Custom URL is? For example, my app could generate a file which I want to display in "Notes" on an iOS device. How can I launch "Notes" and pass it the file?

In the LC dictionary for "launch url", it says that if one tries to launch a file, then the default action for dealing with that file will open, and the calling app will be closed: but that's not what happens when one uses a custom URL. Also, at least on iOS systems, it's normal, when app A opens app B, to see a button at the top left of app B's screen to take the user back to app A. Not sure how all this fits together.

Panos Merakos

Hello Graham,

You need to know/find the custom URL of the app you want to launch. I did some research and found this list of custom urls of known iOS apps (have not tested if they are correct):

https://ios.gadgethacks.com/news/always-updated-list-ios-app-url-scheme-names-0184033/

You also need to "whitelist" the custom URL(s) your app will launch, because they are blocked for security reasons otherwise. You can do so in the iOs standalone settings. This bug report has some useful info:

https://quality.livecode.com/show_bug.cgi?id=21754

Kind regards,
Panos
--

simon

Hi, I have followed this lesson and it worked fine but when I try to use in my own stack it doesn't work (meaning the App doesn't launch when called from the browser) as explained in the post I made in the forum
https://forums.livecode.com/viewtopic.php?f=9&t=37384&p=218703#p218703
I would appreciate any hint to point me what can I do to fix it. Thanks

Panos Merakos

Hello Simon,

Does your app launch if you use the custom url of this lesson (i.e. "webme")? This will allow us to check if the problem is in the custom url you use (I doubt this is the case) or something else in your app. If using the "webme" custom URL scheme does not fix the issue, could you file a bug report at quality.livecode.com and include your stack - or email it directly to me.

Kind regards,
Panos

simon

Dear Panos, as you expected using "webme" doesn't make any difference. Bug report opened:
https://quality.livecode.com/show_bug.cgi?id=23988
Many thanks for your support

simon

With the customary help from Panos I was able to solve the problem.

It is related with using custom plist.

The custom plist has to be modified in order to support the custom URL Scheme as described in the bug report below

https://quality.livecode.com/show_bug.cgi?id=23988

Regards

simon

So now I have another question. If I can open my app from Safari by using webme:// what should I type inside a WhatsApp message in order to add a link that will have the same effect? (opening the App)
Hope I made myself clear enough...
Many thanks for any suggestion

Panos Merakos

Hello Simon,

Hmm, I am not sure if this is possible. So, essentially, you want to be able to launch your app from the WhatsApp app. This would require the WhatsApp app to have your app's custom url scheme whitelisted in its plist, otherwise Apple won't allow that for security purposes. Safari is an exception and can launch other apps without the need to whitelist their custom url schemes in Safari's plist.

Have you seen this with other apps? I mean the ability to launch them from a link in a WhatsApp message.

kind regards,
Panos
--

simon

Hi Panos, let me elaborate on the idea. If I receive a message in WhatsApp with a link pointing, for instance, to my LinkedIn profile and the LinkedIn APP is installed on the phone, when I click such link the LinkedIn APP will open exactly in the page where my profile is. I'd like to achieve something similar, meaning I will send a WhatsApp message to my user which has my APP installed and she/he will click on it and my APP will open...

Panos Merakos

Hello Simon,
Ok, I see what you mean. I _think_ that what happens in this case is that the browser tries to open this LinkedIn link, and since as we said Safari can launch custom url schemes of third party apps without special permissions, it launches the LinkedIn app if it is installed.
And this happens because I believe that if you inspect the page source (i.e. the html code) of a LinkedIn link, it will have a section that launches the LinkedIn app on mobile, if it is installed.

Kind regards,
Panos

simon

Hi Panos, thanks for your explanation which makes total sense. Any ideas to explore as how to achieve my goal? Regards

Panos Merakos

Hello Simon,

I have not tested this, but I believe you could add a webpage to your website, e.g. https://luckro.com/launchiosapp

and in the html code of this webpage make it so it redirects to "webme://" (or whatever is the custom URL scheme of your iOS app)

So the logic is that in the WhatsApp message you send the "https://luckro.com/launchiosapp" link. Then, when the user clicks on this link, it opens with Safari, and it redirects Safari to open "webme://", so this will hopefully launch your app.

Kind regards,
Panos
--

Simon

Panos, this is a great idea, it seems very straightforward. I will try it and report back. Many thanks, best!

simon

Dear Panos, I have said it before but will say it again: you are my hero! Your suggestion works as a charm (tested both on iOS/Safari & Android/Chrome) many thanks! Best, Simon

Panos Merakos

Hello Simon - thank you for the update and your kind words - I am glad this worked :)

Cheers,
Panos

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.