IOS 13 cant handle universallink click when app opened with link click
Asked Answered
G

1

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)
    }  
  }
Gutturalize answered 7/12, 2019 at 1:53 Comment(3)
Have you found any solution for this ?Maclean
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.Daze
Any fix for this?However
A
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

Aigneis answered 7/12, 2019 at 13:33 Comment(6)
Yeah I have scene delegate and appDelegate also.I am adding SceneDelegate to questionGutturalize
Are you accessing the link from Safari? Try to click the link from different sources (chrome, notes, etc) just to identify the issueAigneis
Amazing❗️ You made my day 😊👍Sheepdog
@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 suggestChopstick
@Chopstick what is the crash log? maybe something wrong in the app delegateAigneis
@Omar I found solutions the problems was with the navigations . Thank you I sorted them out.Chopstick

© 2022 - 2024 — McMap. All rights reserved.