Open a SwiftUI app from URL link using URL Scheme
I was wondering if I could do the same as other big companies generally do with their app and websites. You must have noticed that if you click on an Amazon link from your browser to see a specific product then it will open the same in your installed Amazon app instead of the webpage.
So in this tutorial, I will show you how to open an app from the browser with a specific URL using URL Schemes in SwiftUI.
It can be easily done using URL Types of info.plist or info tab of XCode.
If you don’t know how to find that you can check this: How to find info.plist file in Xcode in SwiftUI project
Steps:
After creating your project, your first step is to add the identifier name and URL Schemes.
This image will help you to get there:
Then fill out the URL Types form.
In the Identifier field, you need to enter your project’s Bundle identifier name. It can be found in the general tab shown in the above picture.
This will tell your OS that this App should be opened using that particular URL Scheme.
The next field is URL Schemes. This is the place where you will set the URL for which your app will open.
Like if you set xyz
and open the browser and hit this url xyz://
then the app will open.
For the role, you can set it to viewer if your purpose is to open the app only.
For example, if I do this:
Then the outcome will be like this:
safari cannot open the page because the address is invalid
if you are using iOS 16+ versions. In that case, kindly refer to this tutorial to fix that: URL Scheme is not working in SwiftUI – SolutionIn my next tutorial, I will share how to use the get method and other stuff with these URL Schemes.
Leave a Reply