Ionic推送:在Android应用中找不到GCM项目编号

5
我正在尝试使用ionic.io发送推送通知。以下是我的操作步骤:
  1. 在GCM中创建一个应用并启用GCM API。

enter image description here

  1. 创建凭据并获取API密钥。

enter image description here

  1. 在ionic.io仪表板中创建一个应用程序。
  2. 创建一个安全配置文件并添加API密钥。

enter image description here

  1. ionic.io仪表板中创建一个API令牌。

enter image description here

  1. My source code in app.js which generated by ionic start pushdemo

    .run(function($ionicPlatform) {
    
    $ionicPlatform.ready(function() {
    
    var push = new Ionic.Push({
      "debug": true
    });
    
    push.register(function(token) {
      alert(token.token);
      console.log("Device token:",token.token);
      push.saveToken(token);
    });
    

7.添加推送插件:

ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"

我尝试过在myproject_number周围加上引号和不加引号,它是第一步中的项目编号。

8.将dev_push设置为false

9.通过ionic io init将我的应用程序连接到ionic.io

10.运行ionic run android -lc

发现以下错误信息:

enter image description here

出了什么问题?有人可以帮忙吗?谢谢。

3个回答

1
我遇到了相同的问题,这通常是代理问题造成的。如果您使用代理访问互联网,则需要通过直接使用自己的互联网(例如,如果您使用WIFI),向服务器发出请求。第二步,创建项目目录后,请从控制台直接登录Ionic io,它将要求输入电子邮件和密码,这将使您的应用程序上线。第三步。
ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"

在输入您的项目编号时,请使用引号。 项目编号也称为GCM编号,您的服务器密钥是在相同项目中生成的密钥,即Google控制台,这使您能够使用Google服务。 不要忘记添加Android平台。


不要忘记登录后上传。 - user6356207
对我不起作用。我正在使用wifi。仍然出现“未找到GCM项目号”的错误。 - Bagusflyer
ionic config set gcm_key <your-gcm-project-number> - user6356207
请将上述命令中的“<>”替换为您在Google控制台生成的GCM项目编号。 - user6356207
gcm-project-number 是否类似于 9748xxxxxxxx?这次我遇到了这个错误:Ionic Push:,(调试)发生了意外错误。Ionic Push:,[object Object] - Bagusflyer
然后我不知道发生了什么。显然我输入了正确的GCM项目编号。 - Bagusflyer

1

ionic start pushCall ionic login ionic upload

//打开谷歌控制台 1-创建项目 2-使用谷歌API 1-移动API 2-选择谷歌云消息传递并启用它 3-转到凭证并创建API密钥

//之后添加以下插件

ionic add ionic-platform-web-client ionic plugin add phonegap-plugin-push --variable SENDER_ID="991785317333" (添加GCM号码时不要删除引号)

//添加平台

ionic platform add android ionic io init ionic config set dev_push true

//打开Ionic io 进入设置 1-创建API密钥
2-转到证书并创建安全配置文件名称编辑ID,单击Android并添加GCM密钥 并保存。

//add this code to app.js


angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
 var push = new Ionic.Push({
  "debug": true
    });

   push.register(function(token) {
  console.log("My Device token:",token.token);
  push.saveToken(token);  // persist the token in the Ionic Platform
    });
});
})

//测试是否已正确配置ionic io open launch postman, //然后执行以下操作:

1-create collection give it a valid name
2-in body click on text and select Application/json
it will add header automatically
3-add another header     
key as Authorization
value as bearer followed by your api token from ionic io
4-select "raw " as the format of our json
2-in body section of your collection write
following code
{
"tokens": ["DEV_DEVICE_TOKEN"],
    "profile": "PROFILE_NAME",
    "notification":
     {
    "message": "This is my demo push!"
     }
}

//现在它将在浏览器上提示消息

ionic配置设置gcm_key
ionic配置设置dev_push为false ionic构建安卓

在移动设备上安装您的应用程序并从Postman发送通知

(Mahesh Sampat Nighut) 纳维·孟买


我正在做你在答案中提到的几乎相同的事情。但是我的问题是找不到GCM项目号,尽管我在ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"中添加了该号码。 - Bagusflyer

0

在您的app.js中添加此代码

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
     var push = new Ionic.Push({
      "debug": true
        });

       push.register(function(token) {
      console.log("My Device token:",token.token);
      push.saveToken(token);  // persist the token in the Ionic Platform
        });
    });
    })

别忘了运行下面的命令

ionic config set dev_push true

当你在浏览器上测试时,请将上述命令设置为true,这意味着开发模式。而当你制作apk时,这时你需要将上述命令设置为false。


我在有限模式下运行没有问题。但是我的问题是当我尝试在实际设备上以生产模式运行时。这意味着将dev_push设置为false。 - Bagusflyer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接