IOS10: tapping an action from a local notification does not bring the application to the fore

I am trying to perform an action from a notification. And so far I can call the correct delegate functions, but after clicking on the application it is not brought to the fore.

Relevant Code:

@available(iOS 10.0, *) func registerCategory() -> Void{ print("register category") let callNow = UNNotificationAction(identifier: "call", title: "Call now", options: []) let clear = UNNotificationAction(identifier: "clear", title: "Clear", options: []) let category : UNNotificationCategory = UNNotificationCategory.init(identifier: "IDENT123", actions: [callNow, clear], intentIdentifiers: [], options: []) let center = UNUserNotificationCenter.currentNotificationCenter() center.setNotificationCategories([category]) } @available(iOS 10.0, *) func scheduleNotification(event : String, interval: NSTimeInterval) { print("schedule ", event) let content = UNMutableNotificationContent() content.title = event content.body = "body" content.categoryIdentifier = "CALLINNOTIFICATION" let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: interval, repeats: false) let identifier = "id_"+event let request = UNNotificationRequest.init(identifier: identifier, content: content, trigger: trigger) let center = UNUserNotificationCenter.currentNotificationCenter() center.addNotificationRequest(request) { (error) in } } @available(iOS 10.0, *) func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) { print("willPresent") completionHandler([.Badge, .Alert, .Sound]) } @available(iOS 10.0, *) func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { let notification: UNNotification = response.notification let UUID = notification.request.content.userInfo["UUID"] as! String switch (response.actionIdentifier) { case "COMPLETE": UNUserNotificationCenter.currentNotificationCenter().removeDeliveredNotificationsWithIdentifiers([UUID]) case "CALLIN": let call = Call() CalendarController.sharedInstance.fetchMeetingByUUID(UUID, completion: { (thisMeeting) -> Void in if(!CallIn.Yield(thisMeeting).ConferenceCallNumber.containsString("None")){ call._call(thisMeeting) }else{ //will open detail view, in case that no number were detected NSNotificationCenter.defaultCenter().postNotificationName("OpenDetailViewOfMeeting", object: self, userInfo: ["UUID":UUID]) } }) UNUserNotificationCenter.currentNotificationCenter().removeDeliveredNotificationsWithIdentifiers([UUID]) default: // switch statements must be exhaustive - this condition should never be met log.error("Error: unexpected notification action identifier: \(UUID)") } completionHandler() } 

I can hit the didReceiveNotificationResponse () delegate function with a breakpoint, and it performs some of the actions that I put there, but not as expected (it should launch a device call, instead it just rejects the notification list, and nothing happens, however when I manually open the application again, the call starts, as if there is no permission to open the application from the notification).

+5
source share
1 answer

I myself figured out the reason, so it may be useful to someone in the future. The answer was pretty simple. When creating a notification action, there is this option: options. When you register a category, you need to place it in either .Foreground or .Destructive direction, like this:

 func reisterCategory () { let callNow = UNNotificationAction(identifier: NotificationActions.callNow.rawValue, title: "Call now", options: UNNotificationActionOptions.Foreground) let clear = UNNotificationAction(identifier: NotificationActions.clear.rawValue, title: "Clear", options: UNNotificationActionOptions.Destructive) let category = UNNotificationCategory.init(identifier: "NOTIFICATION", actions: [callNow, clear], intentIdentifiers: [], options: []) let center = UNUserNotificationCenter.currentNotificationCenter() center.setNotificationCategories([category]) } 
+4
source

Source: https://habr.com/ru/post/1257532/


All Articles