Is there a way to detect whether a user is:
- Able to handoff to another device / there is a device in the area with bluetooth on that can accept the handoff
- 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()
}