1

Is there a way to detect whether a user is:

  1. Able to handoff to another device / there is a device in the area with bluetooth on that can accept the handoff
  2. if the user clicked on their handoff browser button to load the page passed

We have an in app web view, and handoff the url a user is on from mobile to desktop. We just want to be able to log if it was able to handoff, and if the user selected the link when it was handed off.

Here's my code:

    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
        webView.userActivity = nil
        if let handoffUrl = webView.url, webView.userActivity == nil && webView.url?.scheme != nil && UIApplication.shared.canOpenURL(handoffUrl) {
            webView.userActivity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
            webView.userActivity?.isEligibleForHandoff = true
            print("//HERE handing off a website - this gets hit even if a user has no devices to handoff to: ", handoffUrl)
            webView.userActivity?.webpageURL = handoffUrl
        }
        webView.userActivity?.becomeCurrent()
    }
    
Ryan
  • 107
  • 7
  • 30
  • Do you need to transfer data from desktop to mobile in this connection? – Mohammad Reza Koohkan Feb 12 '22 at 04:12
  • check out https://developer.apple.com/documentation/foundation/task_management/implementing_handoff_in_your_app and https://www.raywenderlich.com/2240-handoff-tutorial-getting-started – DoTryCatch Feb 12 '22 at 10:02
  • Only the url needs to be passed. I just want to know whether the user actually clicks the handed off url – Ryan Feb 12 '22 at 20:03

0 Answers0