无法在Android上获取EXPO Push令牌 [英] Can not get expo push token on Android

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

问题描述

我正在构建一个基于 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开始博览会,并扫描生成的QR码(使用其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.

如果您没有看到用户名"身份登录,请在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上获取EXPO Push令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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