7

I am trying to handle open apps from universal link click. below ios 13 its working good but for ios 13 its working only app running in background. If app not working foreground or background, clicking link opens app not called continue userActivity function. I also tried to get it in scene delegate willconnnect to delegate. But still not calling My code is below what is wrong?

scene delegate

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  guard let _ = (scene as? UIWindowScene) else { return }

  if connectionOptions.userActivities.first != nil {
    self.scene(scene, continue: userActivity!)
   }
}
    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    continueUserActivity(userActivity: userActivity)
}
func continueUserActivity(userActivity : NSUserActivity){
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        let dataDict:[String: String] = [AppLinkManager.appLinkExtraKey: url.absoluteString]

        NotificationCenter.default.post(name: .didReceiveAppLink, object: nil, userInfo: dataDict)
    }
}

app delegate

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
   if let userActivityDict = launchOptions?[.userActivityDictionary] as? [AnyHashable : Any],
      let userActivity = userActivityDict["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity {
       continueUserActivity(userActivity: userActivity)
   }
    return true
  } 
  func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool  {
      continueUserActivity(userActivity: userActivity)
      return true
   }


func continueUserActivity(userActivity : NSUserActivity){
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        let dataDict:[String: String] = [AppLinkManager.appLinkExtraKey: url.absoluteString]

        NotificationCenter.default.post(name: .didReceiveAppLink, object: nil, userInfo: dataDict)
    }  
  }
3
  • Have you found any solution for this ?
    – Nizzam
    Commented Feb 19, 2020 at 5:52
  • I'm having the same issue. when the app is closed, or swiped from the recent apps and I click my dynamic link the app opens but I do not get the url information. when the app is still running in background or foreground and I click the link everything works as expected, receiving the url correctly.
    – Sergio
    Commented Apr 2, 2020 at 9:25
  • Any fix for this? Commented Aug 10, 2021 at 9:36

1 Answer 1

5

Have you tried implementing continue userActivity function in SceneDelegate:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { }

I faced the same issue when using Firebase DynamicLink and looks like UniversalLinks (and probably several other APIs) use this callback on the SceneDelegate.

So if you're targeting iOS 13 and below try implementing both for SceneDelegate and AppDelegate

6
  • Yeah I have scene delegate and appDelegate also.I am adding SceneDelegate to question
    – nikinci
    Commented Dec 7, 2019 at 19:09
  • Are you accessing the link from Safari? Try to click the link from different sources (chrome, notes, etc) just to identify the issue
    – omar
    Commented Dec 8, 2019 at 12:17
  • Amazing❗️ You made my day 😊👍 Commented May 4, 2020 at 13:11
  • @YassineElBadaoui my app is in iOS 13 , and it does not have scene delegate , it crashes every time a universal link is clicked and app is in inactive state , please suggest
    – iMinion
    Commented May 15, 2020 at 15:10
  • @iMinion what is the crash log? maybe something wrong in the app delegate
    – omar
    Commented May 16, 2020 at 21:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.