I imagine that at some point when you are developing an application you have faced a requirement that it needs to open another application from within the one you are developing. This type of requirements that involve the call of third-party applications is very common, for example when the user wants to make some kind of connection with social networks or applications that have a direct communication with the user such as Uber, Lyft between others. ?♀
That’s why in this post we will be learning about how to Launching Apps in Xamarin Forms!
First, let’s learn some important concepts!
✔ What is a DeepLinking?
Is a type of link that send users directly to an app instead of a website or a store.
An example with which we can apply this type of action is when we want to send the user directly to a specific location within the application, saving time to locate particular sessions. This significantly improves the user experience. You can read more about this here.
✔ What is a Launcher?
Xamarin Essentials gives us the Launcher class, which enables an application to open a URI by the system. This is often used when deep linking into another application’s custom URI schemes. ?
⚠ It’s important not to confuse Open Apps and Open Browsers, Launcher is just for Apps if you want to open browser you can read this article.
To start, Launcher class bring to us some important Async methods that we need to know:
➖ CanOpenAsync: It allow us to know is the App can be opened. Returns a Bool value. Receives a string or Uri as parameters.
➖ OpenAsync: Is responsible to Open our wished App even files!. Receives the following parameters: Uri, string or OpenFileRequest.
➖ TryOpenAsync: This method allow us to Open our wished App and returns if it was supported or not. Receives a string or Uri as parameters.
Practicing the knowledge obtained above, let’s code! ?
In this example we are going to open the Facebook application and this is where Deeplinking enters the stage, since it is the data that will allow us to open the application needed.
⚠ You can search for the Deeplinking they need by searching the developer page of the desired App.
Let’s add a simple Button:
Now, let’s call to the action in an Event:
Additional Platform Setup
In your Info.plist add LSApplicationQueriesSchemes as an Array value and then add the scheme value of your App. In the case of the Facebook scheme is: “fb”. (The ‘fb” was obtained from the deeplinking: fb://)
and doesn’t need additional settings.
And done! you can open your App!
Thanks for reading !!! ?