Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 13 cant handle universallink click when app opened with link click

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)
    }  
  }
like image 506
nikinci Avatar asked Dec 07 '19 01:12

nikinci


People also ask

Why do links Not Open in app Iphone?

Links can only open in-app if the user is signed in. The user should be registered and signed in before expecting links to content to open directly in the mobile app.

How do you open links in their respective apps iOS?

You do this by clicking on the link that appears in the top-right corner of the screen when iOS has opened an app with a Universal Link.


1 Answers

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

like image 52
omar Avatar answered Oct 13 '22 20:10

omar