Search code examples
iosswiftbackground-processuilocalnotificationwatchkit

How trigger background process from Watch on iPhone (trigger: Watch)?


I'd like to add to my Watch app functionality which send to iPhone app a Local Notification (while iPhone app is on the background or iPhone is locked).

I know how to create Local Notification itself.

What Im asking for is way, how to trigger background process (which contains also Local Notification) on iPhone by (for example) tapping on button on Apple Watch.


Solution

  • WKInterfaceController.openParentApplication is the official way to communicate with the iPhone. Documentation.

    You pass parameters in the userInfo dictionary and retrieve results via the reply block.

    On the iPhone the request is handled by appDelegate's handleWatchKitExtensionRequest method. Documentation