Reputation: 798
My team and I are currently developing an iOS app with push notifications.
We have a Rails backend which sends push-Notifications to the iOS application. Everything works as expected.
We have different types of notifications (promotion, general_info, news) we send in our Notification payload as follows:
aps: {
alert: body,
badge: 1,
sound: 'bingbong.aiff'
},
type: type
However, we want the user to specify which types of notifications he wants to receive and which not (with an in-app settings-Menu).
E.g. if the user has deselected the type 'promotion', notifications which include the type 'promotion' will be filtered, so that the user won't get notifications for promotions.
This behavior is similar to the one, the Whatsapp!-App uses to mute groups.
we've found another solution for this one:
Can you mute incoming Push Notifications from the App side [iOS]
But this only works if the user is in the app.
Is it even possible to check the payload and then decide if the push-Notification will be shown to the user when the app is in background / closed?
Thanks in advance!
Upvotes: 0
Views: 665
Reputation: 17409
You can not read payload when notification come ,you can read it in didRecieve
method,
So , For that Create some webService that called when user change in app-setting menu, based on that store in some table, so when next time you send pushnotification filter based on that table..
Upvotes: 0
Reputation: 75058
Your app has no ability to see the push payload while it's in the background, it only receives that data while in the foreground.
To do the kind of filtering you want, you pretty much have to limit at the server side what gets sent out. If you are using a push provider you can usually simply unsubscribe to one of your categories and a push to that category would not be sent to that user.
Upvotes: 2