I have an app that uses deep linking to navigate to a page when a user shares specific content in the app with another user. This is working when the second user has the app already running, but if the app is not running it simply opens the app and remains on the main screen. I know I must be missing something really simple here, but I just can't figure it out and can't find any answers regarding this on google.
My code in AppDelegate.swift:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let urlPath : String = url.path as String!
let urlHost : String = url.host as String!
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(urlHost != "example.com")
{
print("Call Not From Correct Host. Not Continuing...")
return false
}
if(urlPath == "/articles"){
let article: ArticleDetailsViewController = mainStoryboard.instantiateViewController(withIdentifier: "ArticleDetailsViewController") as! ArticleDetailsViewController
self.window?.rootViewController = article
}
self.window?.makeKeyAndVisible()
return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
If the app is installed, the user will be taken to the app via the deep link. If and only if the app is not installed, the click will not go anywhere. Therefore, bidders should only create deep links for users that they know have previously installed the app, based on data from their analytics SDK(s).
By using Android Debug Bridge (ADB) shell commands one can test the deep link flow. It is used to verify if the link navigates to the correct section of your app. This command starts the ADB shell with the VIEW action and specifies the deep link URL to be tested.
Deep links are a type of link that send users directly to an app instead of a website or a store. They are used to send users straight to specific in-app locations, saving users the time and energy locating a particular page themselves – significantly improving the user experience.
In the context of mobile apps, deep linking consists of using a uniform resource identifier (URI) that links to a specific location within a mobile app rather than simply launching the app. Deferred deep linking allows users to deep link to content even if the app is not already installed.
This is correct behavior.
You should handle it in appliction(_: didFinishLaunchingWithOptions:)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if let url = launchOptions[.url] as? URL, let annotation = launchOptions[.annotation] {
return self.application(application, open: url, sourceApplication: launchOptions[.sourceApplication] as? String, annotation: annotation)
}
return true
}
For Swift4.2
if launchOptions != nil{
let launch = launchOptions![UIApplicationLaunchOptionsKey.userActivityDictionary]! as! Dictionary <String,Any>
if ((launch["UIApplicationLaunchOptionsUserActivityKey"]! as! NSUserActivity).webpageURL != nil){
if defaults.bool(forKey: DEFAULTS_IS_FIRST_START){
print((launch["UIApplicationLaunchOptionsUserActivityKey"]! as! NSUserActivity).webpageURL)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With