Removing UILocalNotification from notification tray programmatically

后端 未结 7 1788
再見小時候
再見小時候 2020-12-29 10:29

Is there a way to programmatically remove/dismiss UILocalNotification from Notification Tray. I am able to cancel the notification which removes the notificatio

相关标签:
7条回答
  • 2020-12-29 10:56
    // deletes a pushnotification with userInfo[id] = id
    -(void)deleteLocalPushNotificationWithId:(NSString*)id{
      for(UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]){
        if([[notification.userInfo objectForKey:@"id"] isEqualToString:id]){
            [[UIApplication sharedApplication] cancelLocalNotification:notification];
        }
      }
    }
    
    // deletes all fired pushnotifications
    -(void)clearLocalPushNotifications{
      NSArray *activeNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
    
      // Clear all notifications to remove old notifications
      [[UIApplication sharedApplication] cancelAllLocalNotifications];
    
      // Add back the still relevant notifications
      for (UILocalNotification *notification in activeNotifications) {
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
      }
    }
    
    0 讨论(0)
提交回复
热议问题