1

I've a todo app and I need a notification to be displayed to the watch at the scheduled todo time. How do I do this? I've read that iOS local notification automatically fires notification in the watch. Is it possible? If yes, do I need to add any code in extra to do so?

  • Yeah, you are correct @Naveen. "The operating system is responsible for delivering local notifications at their scheduled times; the app does not have to be running for this to happen." - [Apple Documentation](https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/). You need to add a code for Local Notifications. Get more clear for a particular ToDo from [here](http://stackoverflow.com/questions/20110805/fire-a-notification-at-a-specific-day-and-time-every-week). Hope this might help you. – iYoung Apr 22 '15 at 05:09
  • Thanks @Rajat. Will the notification scene we've made for the watch app appear when the iPhone app fires the local notification? – Naveen George Thoppan Apr 22 '15 at 05:37
  • Yes it will be shown on the watch. – iYoung Apr 22 '15 at 05:44

2 Answers2

2

In watchOS 3, you no longer need a need to use the phone to schedule a notification.

You can now use the new UserNotifications framework to schedule local notifications directly on the watch. These notifications will only appear on and be handled by the watch.

The WWDC 2016 Introduction to Notifications session covers how you can use different types of triggers to fire off your todo notification, such as:

  • Time interval triggers

    // In 2 minutes from now
    UNTimeIntervalNotificationTrigger(timeInterval: 120, repeats: false)
    
    // Repeat every hour starting now
    UNTimeIntervalNotificationTrigger(timeInterval: 3600, repeats: true)
    
  • Calendar triggers

    let dateComponents = DateComponents()
    // Configure dateComponents
    UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
    

The session also covers how to handle actionable notifications on the watch.

1

The concept of a UILocalNotification hasn't changed with WatchKit. The only thing that has changed is that iOS can now decide whether to send a local (or remote) notification to either the iPhone or the Watch. There is no programmatic way to control which of these devices actually displays the notification, though.

To schedule a UILocalNotification from a WatchKit app requires using something like the openParentApplication:reply: class method on WKInterfaceController to have the iPhone app do the actual scheduling. This is because WatchKit doesn't have access to UIApplication, the class that is used to schedule local notifications.

Mike Swanson
  • 3,337
  • 1
  • 17
  • 15