【发布时间】:2020-06-02 22:27:26
【问题描述】:
SDK 版本:37 平台(Android/iOS/web/all):全部
每次我运行 await Notifications.getExpoPushTokenAsync(); 时都会生成相同的令牌。令牌看起来像:ExponentPushToken[NgTr99YO5fy0EQM4R]。我能够收到此令牌的推送通知,因此我知道它的格式正确,我只是对为什么它在应该生成一个新令牌时不断向我推送相同的令牌感到困惑。我错过了什么?
const registerForPushNotificationsAsync = async () => {
if (Constants.isDevice) {
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") {
return;
}
token = await Notifications.getExpoPushTokenAsync();
} 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],
});
}
return token;
};
【问题讨论】:
标签: push-notification expo react-native-push-notification