无法在 Android 上获取博览会推送令牌 [英] Can not get expo push token on Android

查看:32
本文介绍了无法在 Android 上获取博览会推送令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个基于 Expo 的 React 本机应用程序,我还想利用 Expo 的推送与 Firebase 实时数据库结合使用的通知功能.我基本上遵循这里中描述的步骤.在到达必须提取推送通知令牌的部分之前,一切进展顺利.

I am building a React native app which is based on Expo and I want to also take advantage of Expo's push notification capabilities in a combination with Firebase realtime database. I am basically following the steps being described here. Everything was going pretty well before reaching the part where push notification token has to be extracted.

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();

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

It never returns a value and I can not obtain a push token. This is Android specific(Android 7.0) and it doesn't occur on an iPhone (iOS 11.0.2). On the iPhone a token is returned and I successfully store it in the database.

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

What I am doing is to start expo using their CLI and scan the QR code generated(using their client apps for IOS/Android). Then, again in the browser loaded CLI I observe what is happening runtime with the app respectively on the iPhone and on the Android phone. The versions of the packages are as follows:

expo@31.0.2

firebase@5.5.7

react-native@0.57.1​​

我想让它在 Android 上运行,但仍然没有成功.我在 i-net 上看到有些人只是使用 FCM 进行推送通知 但仍不确定.我的理解方式:

I want to get this running on the Android but still with no success. I saw on the i-net that some people just use FCM for Push Notifications but still not sure. The way I understand it:

请注意,FCM 不能用于向 Android Expo 发送消息客户.此外,FCM 目前不适用于 Expo iOS 应用程序.

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.

is that using FCM you can never have the push notifications working for both IOS and Android.

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

EDIT: After an updated of the Android client app, now I am getting a message saying:

[错误:无法获取设备的 GCM 令牌]

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

推荐答案

[错误:无法获取设备的 GCM 令牌]

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

如果您没有登录 expo-cli 也会触发.

Will also trigger if you are not logged in to the expo-cli.

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

Your login status is indicated in the top left corner of Expo Dev Tools.

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

If you don't see LOGGED IN AS "Username", Run expo login in the cli and provide your username and password.

这篇关于无法在 Android 上获取博览会推送令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆