I am working on iOS app which is supported watch as well below is my concerns.
watch os - 5.3.2 and iOS 13.1
I am facing problem with notification actions in watch app. when iPhone app is terminated and if I get a notification in watch , if I tap on action nothing happens.
I am relaying on push notification and for user notification actions I am registering for user notification.
as below
// this I will call in iPhone app code in did finishlaunching with options.
func registerForPushNotifications(withUserInfo userInfo: [AnyHashable: Any]?) {
if #available(iOS 10.0, *) {
self.requestAuthorization(withUserInfo: userInfo)
} else {
registerUserNotificationSettings(withUserInfo: userInfo)
UIApplication.shared.registerForRemoteNotifications()
}
}
func registerUserNotificationSettings() {
let approveAction = UIMutableUserNotificationAction()
approveAction.title = NSLocalizedString("Approve", comment: "Notification approve button title")
approveAction.identifier = "approve"
approveAction.isDestructive = false
approveAction.activationMode = .background
approveAction.isAuthenticationRequired = true
let denyAction = UIMutableUserNotificationAction()
denyAction.title = NSLocalizedString("Deny", comment: "Notification deny button title")
denyAction.identifier = "deny"
denyAction.isDestructive = true
denyAction.activationMode = .background
denyAction.isAuthenticationRequired = true
let signInCategory = UIMutableUserNotificationCategory()
signInCategory.setActions([approveAction, denyAction], for: .default)
signInCategory.identifier = "pushotp"
let categories = NSSet(object: signInCategory) as? Set<UIUserNotificationCategory>
let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: categories)
DispatchQueue.main.async(execute: {
UIApplication.shared.registerUserNotificationSettings(settings)
})
}
Scenarios
When iPhone app is in background and iPhone is locked and watch is in background. If I push a push notification from server , watch displays notification banner with two actions, if I tap any one action , its working fine.
when iPhone app is killed and iPhone locked immmediatly If I send pushnotification , watch displays notification banner with two actions, if I tap any one actions its working fine.
When iPhone app is killed and iPhone locked, kept both watch and iPhone idle for a hour so. then I will activate the watch and push the notification from server, now watch displays banner with two actions, now if I tap on the actions it is not working.
It would be great if you guys tell me what is the correct thing I have to do.
To ensure that the actions are taken in the 3rd use case, please ensure that Notification Payload should have contentAvailable property to YES. So that the application will launch in background. And it will update the notification user actions accordingly.