UNUserNotificationCenter did receive response with completion handler is never called iOS10, swift 2.3

后端 未结 9 1208
春和景丽
春和景丽 2020-12-13 00:03

I am scheduling new notifications in iOS10, like this:

func scheduleNotification (event : Meeting, todaysBadgeCounter: Int) {

    if #available(iOS 10.0, *)         


        
9条回答
  •  情歌与酒
    2020-12-13 01:02

    Make sure your AppDelegate implementing UNUserNotificationCenterDelegate protocol.

    For Swift

    let center = UNUserNotificationCenter.current()
    center.delegate = self
    

    For Objective-c

    //set delegate to self
    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
    

    Assigning delegate to self will trigger following methods.

    // App in foreground
        private func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
          print("willPresent")
          }
    //On Action click
         private func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
          print("didReceive")
          }
    

提交回复
热议问题