0

I am looking for a way to delete some of the notifications from the notification panel when the app is closed. When the app is running in the background or foreground this is quite possible on both Android and iOS.

I have gone through docs and multiple articles to see if this is possible, and I found in android I can do this using a background service. But for iOS I think I'm confused.

Not sure didReceiveRemoteNotification:fetchCompletionHandler can do it when the app is swiped off by the user.

Tharindu
  • 386
  • 3
  • 17
  • If the user is swiped up by the user then you can't run any code as your app is terminated – Paulw11 May 31 '19 at 10:50
  • So user swiped the app is the same as forced killed? But apps like messenger override current push notification to show the message count from a specific user even when the app is not launched. – Tharindu May 31 '19 at 11:16
  • 1
    A VoIP app can use PushKit. With PushKit a terminated app is relaunched when a push arrives. Honestly I wish people wouldn't terminate all of their apps. I spend a lot of time telling people to stop doing it, but they still do. I think they all grew up with Windows crashing every 5 seconds... – Paulw11 May 31 '19 at 11:46
  • I went through the answers and comments of this question (https://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user?rq=1), seems I can't use PushKit since the app is not a VoIP, and it also seems if the use killed the app, it's nearly impossible to relaunch by the system. – Tharindu Jun 02 '19 at 05:40

1 Answers1

0

In ios add the code in appdelegate class

func applicationWillTerminate(_ application: UIApplication) {

    let center = UNUserNotificationCenter.current()
    center.removeAllPendingNotificationRequests()
    center.removeAllDeliveredNotifications()
}