admin管理员组文章数量:1426072
I want to give users an option to be able to unsubscribe from the notifications. I have already gone through the Expo documentation but I am still not sure how to implement it in my code.
Here is what I want to implement:
Notifications.addListener(listener)
EventSubscription
and then remove() (function) -- Unsubscribe the listener from future notifications. Notification
Here is the ponentDidMount
method:
ponentDidMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
Some Help would be very great
Best Regards Musayyab
I want to give users an option to be able to unsubscribe from the notifications. I have already gone through the Expo documentation but I am still not sure how to implement it in my code.
Here is what I want to implement: https://docs.expo.io/versions/latest/sdk/notifications/#eventsubscription
Notifications.addListener(listener)
EventSubscription
and then remove() (function) -- Unsubscribe the listener from future notifications. Notification
Here is the ponentDidMount
method:
ponentDidMount() {
registerForPushNotificationsAsync();
// Handle notifications that are received or selected while the app
// is open. If the app was closed and then opened by tapping the
// notification (rather than just tapping the app icon to open it),
// this function will fire on the next tick after the app starts
// with the notification data.
this._notificationSubscription = Notifications.addListener(this._handleNotification);
}
Some Help would be very great
Best Regards Musayyab
Share Improve this question edited May 13, 2019 at 18:34 Godfrey 1,11115 silver badges17 bronze badges asked Feb 25, 2019 at 14:18 Musayyab NaveedMusayyab Naveed 3656 silver badges15 bronze badges 6-
3
call
this._notificationSubscription.remove()
– bamtheboozle Commented Feb 25, 2019 at 14:20 - Yeah, I was also thinking about that, would it be enough? And what if I am configuring my notifications on another page and I have the button to unsubscribe on another page how will I call the function then? – Musayyab Naveed Commented Feb 25, 2019 at 14:25
- pass it down as a prop – bamtheboozle Commented Feb 25, 2019 at 14:40
-
I am calling
this._notificationSubscription.remove();
but still getting notifications – Musayyab Naveed Commented Feb 25, 2019 at 21:16 -
Yes you will continue to get notifications. When you
remove
,this._handleNotification
shouldn't get called. – 10101010 Commented Feb 26, 2019 at 1:59
1 Answer
Reset to default 5Just a quick reply as I think most answers or ments at least are missing your point. You can stop the app listening for notification by doing this._notificationSubscription.remove(); But what I assume your looking for is a method to unsubscribe the user from all future notifications (what you would generally offer in a settings menu or options menu so you dont spam the user if they request your app to not send them notifications), this can of course be done in most phones from the phones actual settings and as such you app needs to obey this request or app stores like google and apple will stop your app from being allowed to send notifications at all to any user regardless of subscription state.
Currently the only way to handle this is server side for remote notifications, local ones you could just use asyncstorage to store a setting and reference this before pushing any timed notifications. You will want to setup a call to your notifications server to remove the notification token from your database thus preventing your system from sending that device any future notifications.
版权声明:本文标题:javascript - How to unsubscribe(remove a listener) from React Native Expo push notifications - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745407448a2657313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论