【发布时间】:2019-08-06 19:56:22
【问题描述】:
我正在尝试从我的应用程序接收推送通知令牌,但我从未收到令牌。我尝试使用一些警报进行调试,我可以看到在接受通知时我得到了“授权”返回。我只测试了 iOS。
我在跑步
"expo": "^32.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
我尝试使用来自https://docs.expo.io/versions/latest/guides/push-notifications/的指南
由于它不起作用,我尝试了他们从 API 参考中提供的零食:https://docs.expo.io/versions/v32.0.0/sdk/notifications/
小吃:https://snack.expo.io/@documentation/pushnotifications
这是我当前的代码:
static registerForPushNotificationsAsync = async kid => {
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") {
alert("Failed to get push token for push notification!");
return;
}
let token = await Notifications.getExpoPushTokenAsync();
alert("finalstatus " + finalStatus);
alert("existing status " + existingStatus);
alert(token);
// POST the token to your backend server from where you can retrieve it to send push notifications.
return await fetch(`${Api.APIEndpoint}/app/notification`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
token: token,
kid: kid
})
});
} else {
alert("Must use physical device for Push Notifications");
}
};
前两个警报按预期触发(并在我接受时返回“已授予”),但 alert(token) 似乎为空。
我还注意到我被要求提供两个权限。首先,它请求使用通知的权限,然后请求访问照片。我不需要照片的许可,我很好奇它为什么会要求这样做。
据我了解阅读文档,只有 android 设备才需要 FCM?我也需要它在 android 上工作,但我想先让它在一个平台上工作,然后继续。
我使用 Testflight 在我的 iPhone 上安装了该应用程序。令牌是否仅在应用被批准进入应用商店后“出现”?
也许我在文档中遗漏了一些其他内容。
我们将不胜感激任何帮助或指出正确的方向。
【问题讨论】:
标签: ios react-native expo