【发布时间】:2021-06-08 15:06:18
【问题描述】:
我使用 expo 推送系统设置了推送通知,并且在通过 ExpoGo 使用该应用程序时效果很好。但是在Play商店安装的应用程序中,它不起作用。调试应用程序我发现
token = (await Notifications.getExpoPushTokenAsync()).data;
没有返回任何内容,因为它之后的警报从未运行。
async function registerForPushNotificationsAsync() {
let token;
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
alert('1')
token = (await Notifications.getExpoPushTokenAsync()).data;
alert('2')
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
//sending the token to my api
api.put('xxx', {
notification_token: token,
});
}
我该怎么办?我有什么遗漏吗?我只是使用了文档中给出的代码https://docs.expo.io/push-notifications/overview/
【问题讨论】:
标签: android reactjs react-native expo push