【发布时间】:2020-06-02 19:14:44
【问题描述】:
首先,我将非常感谢您的帮助。
我正在尝试使用 expo-bare 工作流来实现 expo 推送通知。当我运行应用程序时,它给了我这样的错误,所以我无法获得令牌。
错误[TypeError: null is not an object (evaluating '_ExponentNotifications.default.getExponentPushTokenAsync')]
这是我的代码:
import { Notifications } from "expo";
import * as Permissions from "expo-permissions";
import Constants from "expo-constants";
export const getToken = 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") {
console.log("Failed to get push token for push notification!");
return;
}
token = await Notifications.getExpoPushTokenAsync();
}
else {
console.log("Must use physical device for Push Notifications");
}
return token;
};
【问题讨论】:
-
裸工作流使用 expo-notifications 包 - github.com/expo/expo/tree/master/packages/expo-notifications
-
我按照您评论的指示进行操作,先生。也许我可以尝试你在下面分享代码的方式,我会通知你。谢谢你的帮助先生。
标签: react-native push-notification expo