2 kind of notifications ..." /> 2 kind of notifications ..."> 2 kind of notifications ...">

IOS - Enable/disable A Group Of Notifications Based On Switch Value

I have a bunch of notifications in my iOS app which can be placed in groups:

  • Group 1: "Events" -> 2 kind of notifications
  • Group 2: "Promotions" -> 3 kind of notifications .....

In my setting screen I have a switch for each notification group. I want to enable disable the group of notification based on the value of the respective switch : ex: Events switch is turned off so I don't want to receive the 2 type of notifications of this group.

It easily handled when the app is on foreground by using the completionHandler of the function:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

But I can't find a way to block those notification when the app is in background.

I read that to deal with background notifications like that. I have to store in my own server the value of the switches for each user and send or not the notification based on the value on the server.

It is the right way to do that or am I missing something in my app.



You can't interact with notifications that are sent while your app is not active, they will be received either way since they have been designed that way.

The fact that you can do that while the app is active is actually aimed at developers to allow them to use custom notification handling while the app is active instead of a method to filter them.

The best way to handle that is the one you proposed, the backend should filter what types of notifications to send to the user, and send only those to the user.

source: stackoverflow.com