gpt4 book ai didi

push-notification - 无法在 Android 上获取 expo push token

转载 作者:行者123 更新时间:2023-12-04 01:21:43 24 4
gpt4 key购买 nike

我正在构建一个基于 Expo 的 React native 应用程序我还想结合使用 Expo 的推送通知功能 Firebase realtime database .我基本上遵循描述的步骤 here .在到达必须提取推送通知 token 的部分之前,一切都进行得很顺利。

registerForPushNotificationsAsync = async (userInfo) => {
// ... Stuff

// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
console.log("Expo token: " + token);
var updates = {}
updates['/expoToken'] = token
firebase.database().ref('Users').child(userInfo.user.uid).update(updates)
}

此行出现问题:

let token = await Notifications.getExpoPushTokenAsync();

它从不返回值,我无法获得推送 token 。 这是 Android 特定的(Android 7.0),不会出现在 iPhone (iOS 11.0.2) 上。在 iPhone 上返回一个 token ,我成功地将它存储在数据库中。

我正在做的是使用他们的 CLI 开始 expo 并扫描生成的二维码(使用他们的 IOS/Android 客户端应用程序)。然后,再次在浏览器加载的 CLI 中,我分别在 iPhone 和 Android 手机上观察应用程序在运行时发生了什么。包的版本如下:

expo@31.0.2

firebase@5.5.7

react-native@0.57.1​​

我想让它在 Android 上运行,但仍然没有成功。我在i-net上看到有人直接用FCM for Push Notifications但仍然不确定。我的理解方式:

Note that FCM cannot be used to send messages to the Android Expo Client. Also, FCM is not currently available for Expo iOS apps.

是使用 FCM 永远无法让推送通知同时适用于 IOS 和 Android。

编辑:更新 Android 客户端应用程序后,现在我收到一条消息:

[Error: Couldn't get GCM token for device]

最佳答案

[Error: Couldn't get GCM token for device]

如果您没有登录到 expo-cli,也会触发。

您的登录状态显示在 Expo Dev Tools 的左上角。

如果您没有看到 LOGGED IN AS "Username",请在 cli 中运行 expo login 并提供您的用户名和密码。

关于push-notification - 无法在 Android 上获取 expo push token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53199472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com