1

I have an iOS 10 app and watchOS 3 extension that uses iOS 10 User Notifications Framework. The local notification is scheduled from the iOS app, and is shown on the watch when the iPhone is locked, and shown on the iOS app on the lock screen if I raise my iPhone, and don't respond to the watch. The iOS notification have three background action buttons.

enter image description here

If I respond to the notification on my iPhone, the userNotificationCenter(_:didReceive:withCompletionHandler:) UNUserNotificationCenter delegate method is called correctly. But if I instead tap on one of the action buttons on my watch, the function is not called.

According to Apple's App Programming Guide for watchOS, under the section Responding to Selected Actions: For background actions, the handling of actions depends on where the notification was scheduled:For local notifications scheduled on iPhone, background actions are handled by your iOS app regardless of which device displayed the notification.

This is not happening, and I don't know why. Have anyone got this working from the watchOS?

Ivan C Myrvold
  • 680
  • 7
  • 23

1 Answers1

2

It looks like I didn't put the correct options in the UNNotificationAction. The options should be an empty array, instead of the .foreground I had mistakenly put there. So for e.g. the Just Practice button, the correct action for it to be background is:

let justPracticeAction = UNNotificationAction(identifier: "justPractice", title: "Just Practice", options: [])

Ivan C Myrvold
  • 680
  • 7
  • 23
  • I'm really glad you followed up on your own question. Just saved me a huge headache. – Erik Sep 21 '17 at 10:45