Deep Linking to Pages Inside Your App #No 1 Premium Url Shortener

Deep Linking to Pages Inside Your App #No 1 Premium Url Shortener

12.Oct.2021

One rule in writing blog posts or articles is to make them easily scannable for the reader. With an article like this, it could be very easy for someone to close out of the page when they see something like this:

I wanted to share with you some deep linking concepts that I’ve used when writing my iOS apps. If you use your iPhone or Android API’s correctly, then you can instruct users where to go in your app without having to send them through a series of screens before finally arriving at their destination. It is especially useful if your app has multiple pages and it would be impractical (or sometimes impossible) for you to send users straight there via URL parameters. And because everything in our app lives inside the browser, deep linking is an invaluable tool for providing links out of the web browser to other pages in our apps.

This can be done with making your Link URLs look like this: #bookmarkscreen#page=home_screen_view . It’s actually not as long as how it first reads–it should break up into pieces that are easier to read. And if you follow along with me, then you can implement what I’ve done anywhere that you have screens within your own app. The example code will be using iOS, but there are similar APIs on Android. ##

What does it do? Instead of deep linking directly to page 2 of your app (which may or may not exist), you can instead deep link to a specific screen inside your app, which makes it much easier for the user to go where they want to go. All you have to do is build what’s called a “Custom URL scheme” and make sure that your app knows what screen to send them to.

What are examples of this? Examples would be something like #home , or #login , or even #messages . These are all custom URL schemes that I use within my iOS apps. They may not mean anything by themselves, but when used with other APIs in conjunction with them, they become very powerful tools. ##

How do I implement this? We need to change the way we think about URLs. Instead of a page number, you’ll be using a custom URL scheme instead. Here are the steps that I use:

 

1.) Make sure your iOS app knows what screen it is on

In order for iOS to deep link to a specific page, it first needs to know where it currently is inside your application. In order to do this, you must build a “Custom URL Scheme” and let your app know what routes / screens exist within your app so that it can properly route users around as they navigate throught he different sections of your app. If you don’t currently have one set up and want one set up, then you’re in the right place.

ALWAYS MAKE SURE WHEN SETTING UP A NEW URL SCHEME THAT YOU WRITE IT DOWN ON PAPER AND SAVE IT SOMEWHERE OTHER THAN YOUR COMPUTER! IF YOU DON'T, THEN YOU WILL FORGET THE CUSTOM URL SCHEME AND WON'T BE ABLE TO GET BACK INTO YOUR APP OR DEVELOPMENT ENVIRONMENT WITHOUT HAVING TO LOSE ALL OF YOUR PROGRESS WITHIN AN HOUR OR TWO OF WORK!! THIS IS EXTREMELY IMPORTANT!!! I CANNOT STRESS ENOUGH HOW MUCH AN ISSUE THIS CAN BECOME OVER TIME.

 

2.) Setup a Custom URL Scheme in Xcode

Once you’ve got your scheme written down, find the Project Navigator in Xcode. Click on ‘Info’ from the top menubar, and choose ‘Configure App’ under the Custom URL Schemes tab. Click add and type in your custom url scheme (in this case, it would be #home ) and click ‘Done’ when finished. Make sure that there are no typos in there!

3.) Set up a Deep Link to a Page in Your App

You should now see your custom url scheme in the list of schemes along with Apple's default ones that you don't want. Now go back to your app, and go into the app's main .js file. Add a new variable to your code that stores your custom URL scheme name (click on 'global' in Xcode if you can't easily find it), and make sure to set it equal to the one you added earlier.

Now go back up to where you are setting up your Deep Links , and instead of using #bookmarkscreen#page=home_screen_view , use #myRouteNameHere#page=pageNumber where pageNumber is however many pages deep you want them inside your app. This will be something like 0 for home, 1 for about, 2 for login, or anything else you decide!

This may seem complicated at first glance–and if it does, then try to set up a very simple app and start building the processes within it. This is something you will use often throughout developing your own apps, so it's important to get used to these little tricks.

1.) Remove the Curly Braces {} from all of your variable settings in this code template: deep-link-template.js . You must do this or nothing will work after you paste the code into your app!

2.) Locate where you are currently setting up your Deep Links , and instead of using #bookmarkscreen#page=home_screen_view , use #myRouteNameHere#page=pageNumber where pageNumber is however many pages deep you want them inside your app. This will be something like 0 for home, 1 for about, 2 for login, or anything else you decide!

3.) Paste the code into your app's main .js file.

4.) Test it out and make sure that everything is working correctly!!!!

5.) You now have a fully working, deep-linked app!

 

How do I make sure it works? This one is pretty straightforward. Just click the link (or put it as your home screen if you're on Android) and make sure that it takes you to the correct page in your app! If not, then go back into Xcode and try testing out your URL scheme to ensure that everything is set up properly. Note: this will only work for iOS 8+, and there's no way around that unless Apple allows custom schemes for older versions of iOS like they do with Twitter.

 

Want more cool stuff like this? Click here to signup for our email list!! We have all sorts of goodies in store for you :D https://tinyletter.com/BellaCanCode

 

Author's Twitter: @bellacan_

Twitter handle used to advertise this article to students / other users interested in app development: @CodingWithTiney

Twitter handle that is mentioned in the article as having gone through the process of setting up a custom URL scheme before learning it from me / us, thus saving them time and hassle: @That_Round_Tuit (referring to @ThatRound

We are social