简体   繁体   English

Android不会从新的Parse Server接收推送通知

[英]Android doesn't receive push notifications from new Parse Server

I'm migrating my Android and iOS apps from parse.com to Parse Server (by the way I'm using a Parse test app but I guess it's not relevant to this issue). 我正在将我的Android和iOS应用程序从parse.com迁移到Parse Server(通过我使用Parse测试应用程序的方式,但我想这与此问题无关)。 After the migration, everything is working well but the push notifications to Android device (they are working well to my iOS app). 迁移后,一切正常,但向Android设备的推送通知(对我的iOS应用程序运行良好)。

This is what I've done so far. 到目前为止,这是我所做的。

1. In my Parse Server code (on Digital Ocean by the way), in /home/parse/index.js I've initialized Parse Server this way: 1.在我的Parse Server代码中(顺便说一下,在Digital Ocean上),在/home/parse/index.js中,我以这种方式初始化了Parse Server:

var api = new ParseServer({  
  databaseURI: databaseUri || '<my mongodb url>',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || '<my app ID>',
  masterKey: process.env.MASTER_KEY || '<my master Key>',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
  push: {
    android: {
        senderId: '<my GCM sender Id>',
        apiKey: '<my GCM API Key>'
      },
    ios: [{
      pfx: '/home/parse/<my dev P12>',  
      passphrase: '',
      cert: '',
      key: '',
      bundleId: '<my bundle ID>',
      production: false
    },
    {
      pfx: '/home/parse/<my prod P12>',  
      passphrase: '',
      cert: '',
      key: '',
      bundleId: '<my bundle ID>',
      production: true
    }]
  }
});

I've taken "my GCM sender ID" from my Google Developer Consoler, it's the 12 digits number from Settings > Project number. 我从Google Developer Console中获取了“我的GCM发送者ID”,它是“设置”>“项目编号”中的12位数字。

I've tried with 3 different "my GCM API Key", one without app restrictions, one available only for my android/debug.keystore and one available only for my app keystore. 我尝试使用3种不同的“我的GCM API密钥”,一种没有应用程序限制,一种仅适用于我的android / debug.keystore,一种仅适用于我的应用程序密钥库。

I've checked that I have selected this app in my Google Developer console and that my package id is correct in all places. 我已检查自己是否已在Google Developer控制台中选择了此应用,并且我的软件包ID在所有地方都是正确的。

2. Once I've made this change I've restarted Parse Server with 2.进行此更改后,我将使用重新启动Parse Server

pm2 delete all // this with parse user
pm2 start ecosystem.json // this with parse user
pm2 save // this with parse user
sudo service nginx restart //this with my sudo user

3. In Android I'm initializing Parse this way: 3.在Android中,这种方式初始化Parse:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.enableLocalDatastore(app);
    // Old version
    Parse.initialize(app, "<my app id>", "<my client key>");
    // New version
    //Parse.initialize(new Parse.Configuration.Builder(ctxt)
    //        .applicationId("<my app id>")
    //        .clientKey(null)
    //        .server("https://<my new server>/parse/")
    //        .build()
    //);
    ParseUser.enableRevocableSessionInBackground();
}

I'm not initializing with the new method because it's crashing (this is the issue of another question Android switch from Parse to Parse Server crashes ), but I guess this initialization doesn't affect the push notifications. 我没有用新方法初始化,因为它崩溃了(这是Android从Parse切换到Parse Server crashes的另一个问题),但是我猜想这种初始化不会影响推送通知。

4. In Android I've added this to my Android Manifest: 4.在Android中,我已将此添加到我的Android清单中:

<meta-data android:name="com.parse.push.gcm_sender_id"
                   android:value="id:<my GCM sender Id>" />;

The rest of my manifest and my GCM configuration is the same I had before the migration. 我清单的其余部分和GCM配置与迁移之前的相同。

5. And as a summary . 5.并作总结

With old parse.com push notifications worked well with Android and iOS. 使用旧的parse.com,推送通知可以在Android和iOS上正常运行。

With new Parse Server and the code described above iOS push notifications are working well. 使用新的Parse Server和上述代码,iOS推送通知可以正常运行。

With new Parse Server and the code described above Android push notifications are not being received. 使用新的Parse Server和上述代码,将不会收到Android推送通知。

With my new Parse Dashboard installed in Digital Ocean when sending push notifications both to iOS and to Android Dashboard gives a Saved! 当我在Digital Ocean中安装了新的Parse Dashboard时,向iOS和Android Dashboard发送推送通知时都可以保存! what makes me thing it's a problem with my Android app and not with my Parse Dashboard/Parse Server configuration. 是什么让我觉得这是我的Android应用程序而不是我的Parse Dashboard / Parse Server配置的问题。

What am I missing here? 我在这里想念什么?

you can try using " CURL " to specified only " android " device. 您可以尝试使用“ CURL ”仅指定“ android ”设备。

curl -X POST \
    -H "X-Parse-Application-Id: you_app_id" \
    -H "X-Parse-Master-Key: your_master_key" \
    -H "Content-Type: application/json" \
    -d '{
          "where": {
            "deviceType": {
              "$in": [
                "android"
              ]
            }
          },
          "data": {
            "title": "The Shining",
            "alert": "All work and no play makes Jack a dull boy."
          }
        }'\   http://your_server_address/parse/push

Then you can find out the exactly what is wrong. 然后,您可以找出确切的问题所在。

Make sure that your Parse SDK libraries are updated! 确保您的Parse SDK库已更新!

I was having a bunch of trouble getting Android notifications pushed from Parse Dashboard too, but it was all resolved when I updated my libraries to Parse 1.13.0 and Bolts 1.4.0. 我也很难从Parse Dashboard推送Android通知,但是当我将库更新为Parse 1.13.0和Bolts 1.4.0时,所有问题都得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM