Search code examples
iosapple-push-notificationswatchkitwatchos-2watchos-simulator

Create Watchkit notification programmatically


I'm looking to push a notification to the Apple Watch at a specific time. I was able to display a static message on the simulator using an apns file, but I'd like to set the data and time of the notification in the controller.

I heard I might not be able to do this on a simulator, but if I got a real phone and watch, how would it work?


Solution

  • So, you want to do something in the watch app extension and based on the results, schedule a UILocalNotification that will be sent to the phone at some point?

    You cannot directly schedule a UILocalNotification from the watch because you don't have access to the UIApplication object. See Apple staff comment here.

    However, using Watch Connectivity, you could send a message from the watch to the phone and have the phone app create and schedule it in the background. The watch will display the notification iff the phone is locked at the trigger time. The watch's notification scene will be invoked in that case.