Skip to content

Instantly share code, notes, and snippets.

@e-sung
Created January 19, 2020 02:06
Show Gist options
  • Save e-sung/96f599c1d908fc5ddd39fe9112f30fc7 to your computer and use it in GitHub Desktop.
Save e-sung/96f599c1d908fc5ddd39fe9112f30fc7 to your computer and use it in GitHub Desktop.
Protocol that enables basic HandOff feature
public protocol HandOffable {
func setUpHandOff(for url: URL?)
}
extension HandOffable where Self: UIViewController {
public func setUpHandOff(for url: URL?) {
guard let url = url else { return }
guard let activtiyType = Bundle.main.bundleIdentifier else { return }
userActivity = NSUserActivity(activityType: activtiyType)
userActivity?.isEligibleForHandoff = true
userActivity?.webpageURL = url
userActivity?.becomeCurrent()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment