Reputation: 1235
I have a bunch of notifications in my iOS app which can be placed in groups:
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.
Upvotes: 0
Views: 886
Reputation: 4552
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.
Upvotes: 2
Reputation: 56
Yes you are on your right way. You have to store in your backend the switch values (On/Off) and send push notifications depending on that values.
Upvotes: 0