Home > OS >  Who handles the notification in iOS? - really React Native
Who handles the notification in iOS? - really React Native

Time:11-14

I have a doubt, I've searched and didn't find the answer, I have implemented notification in my app, is it possible to have a cancel notification in the app or it is only a system option?

When the user opens my app on the third screen it asks about sending notifications, but what if the user doesn't want to receive those notifications anymore, does he need to go to iOS settings or can I do this from the app?

Thanks for your time

CodePudding user response:

If you've used react-native-push-notification or @react-native-community/push-notification-ios then there has a way to remove notification from notification center.

you can use this code to remove all natification

PushNotification.removeAllDeliveredNotifications();

Removes the specified notifications from Notification Center

PushNotification.removeDeliveredNotifications(identifiers);

check out official doc for more detail

packages: https://www.npmjs.com/package/react-native-push-notification https://www.npmjs.com/package/@react-native-community/push-notification-ios

CodePudding user response:

If you no longer needed to receive notifications in your app, it's better to handle the logic in your backend. When the user denies permission, remove the push token from the server. If you only want to remove certain types of notifications, instead of removing tokens, you can set a flag on backend logic to enable/disable certain notifications.

If you really want to do this on the client-side, you can use data-only notifications of FCM or a similar kind, where you have the control to present notifications as local notifications. Basically, a background listener will be triggered when you receive a data-only notification and OS won't present notification. You need to create a local notification and present it according to the data you receive. Here you can add your logic to filter notifications based on User's choice

  • Related