Implementing Handoff Between iPhone and Mac
Handoff between iPhone and Mac is built on the same NSUserActivity foundation as Handoff between iOS devices. However, there's a significant difference: on Mac, the application must be native (AppKit or Catalyst) or a PWA through Safari. A website version with the same domain through Universal Links can continue activity from iPhone via Safari to Mac — this is a separate scenario.
Mac-Side Specifics
If the application supports Mac through Mac Catalyst, most of the code is shared — the iOS NSUserActivity implementation works there as well. The processing point is AppDelegate.application(_:continue:restorationHandler:), which is present in Catalyst unchanged.
For a native Mac application (AppKit), we receive activity in applicationWillContinueUserActivity(_:) and application(_:continue:restorationHandler:) of the NSApplication delegate:
// NSApplicationDelegate
func application(_ application: NSApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
guard userActivity.activityType == "com.myapp.editing-document",
let docId = userActivity.userInfo?["documentId"] as? String else {
return false
}
DocumentManager.shared.openDocument(id: docId)
return true
}
Handoff Through Browser: Universal Links + Web Credentials
If the Mac version of the application is a website rather than a native application, Handoff works through Safari. The iPhone application creates NSUserActivity with webpageURL:
let activity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
activity.webpageURL = URL(string: "https://myapp.com/documents/\(documentId)")
activity.isEligibleForHandoff = true
self.userActivity = activity
activity.becomeCurrent()
Mac Safari will open this URL. For the reverse — opening the iPhone application from Mac Safari — you need Universal Links with apple-app-site-association. This is a separate setup process, not directly related to NSUserActivity.
Continuity Camera and AirDrop Are Not the Same
A common misconception during the design phase: clients call any synchronization between iPhone and Mac "Handoff". Technically:
- Handoff — continuation of current activity (open document, position in list)
- Continuity Camera — using iPhone as a webcam or scanner for Mac
- AirDrop — one-time file transfer
- iCloud sync — background data synchronization
These are different frameworks with different APIs. During the design phase, it's important to clarify what the client actually needs.
Testing
Handoff requires two physical devices with the same Apple ID, Wi-Fi in the same network, and Bluetooth enabled. Simulator — only for testing NSUserActivity handling logic, not for Handoff itself. A characteristic error: activity doesn't appear on Mac because the Bundle ID in Capabilities doesn't match between iOS and Mac targets.
What's Included
-
NSUserActivityon iOS with correctuserInfoandneedsSave - Handling on Mac (Catalyst or AppKit)
- Optionally:
webpageURLfor Safari → Safari scenario - Capabilities and entitlements configuration on both targets
- Testing on physical devices
Timeline
3–5 days depending on the complexity of the state that needs to be transferred and the availability of a Mac target in the project. Pricing is calculated individually.







