【发布时间】:2019-04-23 11:48:36
【问题描述】:
我已经搜索了很多关于此错误的信息,但我不断收到“无法获取设备的 GCM 令牌”
1- 我试过 expo start 然后运行项目 2- 我已登录我的 expo 帐户,我可以在 expo 开发工具中看到我的名字,但没有区别 3-我已将 FCM 添加到我的项目并将 FCM 的服务密钥发送到 expo 服务器 4-我删除了我的节点模块文件夹并运行 npm install 5- 我在 Android 设备上运行
提前谢谢你
Packages.js:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
"private": true
}
App.js 请求 Token 代码:
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return;
}
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
console.log(token);
this.setState({token })
}
app.json:
{
"expo": {
"name": "hamid",
"slug": "expo_test3",
"privacy": "public",
"sdkVersion": "32.0.0",
"platforms": [
"ios",
"android"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"android": {
"googleServicesFile" : "./google-services.json",
"package": "com.yourcompany.hamidtestapp"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
【问题讨论】:
-
你用的是真正的安卓手机吗?
-
@hongdevelop ,是的,我已经将我的 Android 手机连接到 pc 和 Actullay 我没有使用模拟器。
-
只是为了确认一下,您是否通过
expo push:android:upload --api-key your-token-here上传了 FCM 密钥,并且为了清楚起见,这是一个未弹出的项目,对吗? -
@hongdevelop ,是的,我上传了我的密钥,然后我尝试获取我的设备令牌。只是为了确保,你看到我的 App.js 代码了吗?代码没有错,对吗?
标签: javascript react-native google-cloud-messaging expo react-native-fcm