在开发环境中(当应用程序通过QR Code在android设备上运行时),成功获取了推送通知令牌。但是在构建应用程序并将其安装到同一设备后,便不会检索令牌。
我正在使用Expo docs中提供的示例代码来获取令牌。
useEffect(() => {
registerForPushNotifications();
}, [])
registerForPushNotifications = async () => {
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
const token = await Notifications.getExpoPushTokenAsync();
let body = new FormData();
body.append('token', token);
await ApiPublicForm.post('token/index.php', body)
.then(function (response) {
// console.log(response);
})
.catch(function (error) {
// console.log(error);
});
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === 'android') {
Notifications.createChannelAndroidAsync('default', {
name: 'default',
sound: true,
priority: 'max',
vibrate: [0, 250, 250, 250],
});
}
};
我的app.json
"android": {
"permissions": [
"NOTIFICATIONS"
],
"versionCode": 3
}
答案 0 :(得分:0)
得到问题的答案 您必须按照此链接中提到的步骤在独立应用https://docs.expo.io/push-notifications/using-fcm/
中处理推送通知