ARTICLE AD BOX
I am building an iOS app that includes a Safari Web Extension and a companion Apple Watch App.
My goal is simple: When the user taps the button in the Safari Extension popup, I want to send a message (e.g., the current timestamp) to the Apple Watch.
The Setup:
iOS 26.2 / Xcode 26.2
Target 1: iOS Main App (activates WCSession successfully).
Target 2: Safari Web Extension (Manifest V3, using SafariWebExtensionHandler).
Target 3: Watch App.
The Problem:
While WatchConnectivity works perfectly from the main iOS App, it fails immediately when called from the SafariWebExtensionHandler. It seems like the extension process is sandboxed in a way that prevents it from connecting to the Watch Connectivity Daemon (com.apple.wcd).
The Trigger (JavaScript):
The Swift logic is triggered via Native Messaging from the extension's popup (popup.js) when the user taps a button. I have the "nativeMessaging" permission enabled in my manifest.json.
The Code (Extension Handler):
I am using a Singleton to manage the session to avoid race conditions during the short lifecycle of the extension.
The Logs:
The logs clearly show an XPC interruption immediately after trying to connect to com.apple.wcd. It retries 5 times and then fails.
What I have tried:
Direct Communication: Using sendMessage and transferUserInfo directly from the Extension. Result: NSXPCConnectionInterrupted.
App Groups (Relay):
I successfully implemented a relay using App Groups (UserDefaults(suiteName: ...)).
The Extension writes the data to the shared group.
The Main iOS App observes the UserDefaults (via KVO or Darwin Notifications) and sends the data to the Watch.
Issue: This only works if the iOS Main App is running in the background. If the user force-quits the main app (or iOS suspends it aggressively), the relay stops working because the Extension cannot wake up the Main App.
My Question:
Is it technically possible for a Safari Web Extension on iOS to communicate directly with WatchConnectivity? Or is this a hard sandbox limitation by Apple?
If it is a hard limitation, is there any way for a Safari Extension to wake up its parent iOS App in the background to perform the transfer, even if the parent app has been killed?
