IOS Xcode Custom URL Schema

First of all, I know how to create custom schemes in iOS, and I know how to open my application from a website using the javascript setTimeout method.

I have an application that uses a custom URL scheme and works great. What he does, he sends the message http://testsite.com/QueryStrings to other users in the contact list (predefined) and when these web links are clicked in sms, this happens:

  • Open the link in Safari
  • Open the application if it is installed using a custom url using setTimeout
  • If it is not installed, go to the regular page of the website

I wanted to actually open the application directly from SMS, if it is installed, but for this I need to send my custom URL scheme in SMS, this is not an option, because if the application is not installed, this message will not work like this, weblink is the only one option at the moment.

Today I installed SoundCloud and accidentally noticed that this happens when http: // m. soundcloud.com / ... url is sent via SMS and when you click on the link it opens the application (if installed) directly not Safari (for me this is strange).

So I was wondering why their application is open from a web link without opening Safari. I was looking for her, but I could not find a solution to my problem. I also attach a screenshot from my mobile phone, where we click and hold the link in the message application, opening the "SoundCloud" option. Since SoundCloud has registered an http link that will be processed automatically in the application. Help the guys

SoundCloud Open Screenshot

+5
source share
1 answer

The answer to this problem is to use Associated Domains (but after 9.2 we should use Universal Links to achieve this).

Before Universal Links, the main mechanism for opening an application when it was installed was an attempt to redirect to the application URI scheme (registered in PLIST applications like this) in Safari. This put the routing logic in Safari, but there was no way to check if the application was installed or not.

iOS 9 Universal Links were designed to fix this. Instead of opening Safari first when you click the link, iOS checks to see if a universal link has been registered for the domain associated with the link, and then check if the corresponding application is installed. If the application is installed, it will open. If not, Safari will open and the http (s) link will be downloaded.

Functionally, this allows you to have one link that will either open your application or open your mobile site.

Configure the application to register approved domains

  • Register your application at developers.apple.com
  • Include 'Linked Domains in your App ID
  • Enable Linked Domain in Xcode Project
  • Add the correct domain right
  • Make sure the permissions file is included in build

Set up your website to host the apple-app-site-association file

  • Buy a domain name or choose from an existing one
  • Get SSL certificate for domain name
  • Create a structured JSON file for the Apple-app-site-association.
  • Sign JSON file with SSL certificate
  • Configure file server

Apple launched Universal Links on iOS 9.0, which moves application routing to the OS so that developers don’t have to worry about doing routing in Javascript.

Getting the universal URL in the application

URI schemes got the deep link URL through openUrl in the application’s deletion. Generic links get their data using another code: continueUserActivity . This new delegate method is used for several application transitions, from Spotlight to Universal Links, and is likely to see a couple more use cases introduced in future versions of the OS.

Below is a snippet of code that you can use to get the full URL of the universal link that the application opened.

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler { if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { NSString *myUrl = [userActivity.webpageURL absoluteString]; // parse URL string or access query params } return YES; } 

Source: https://blog.branch.io/how-to-setup-universal-links-to-deep-link-on-apple-ios-9

+2
source

Source: https://habr.com/ru/post/1241577/


All Articles