gpt4 book ai didi

push-notification - 使用 react native 获取设备 token

转载 作者:行者123 更新时间:2023-12-03 14:43:39 28 4
gpt4 key购买 nike

有什么方法可以通过 React Native 按需获取通知的设备 token ?从文档看来, token 公开的唯一时间是在 PushNotification 注册事件上。

更一般地说,处理设备 token 的常见做法是什么?

如果一个用户登录我的应用程序,该应用程序会从 PushNotification 请求权限,注册事件被触发,我可以将该设备与登录用户相关联。到目前为止一切顺利,但是如果该用户注销,并且我打破该关联以停止通知,当另一个用户登录时我该怎么办?该应用程序已经拥有权限,因此注册不会再次触发。如何获取设备 token 以将其与新用户关联?

还是我想错了?

最佳答案

看来我的假设是 register事件仅在用户授予访问权限时触发。 register事件将响应对 requestPermissions 的调用而触发。是否提示用户。因此,通过请求权限并响应 register应用程序加载时的事件,您始终可以获取设备 ID。像这样:

PushNotificationIOS.addEventListener('register', (token) => {

... store or use the token here ...

});

PushNotificationIOS.requestPermissions();

关于push-notification - 使用 react native 获取设备 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35387227/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com