【问题标题】:Push-Notifications not working / Heroku-mLab推送通知不起作用 / Heroku-mLab
【发布时间】:2016-11-25 05:39:55
【问题描述】:

我已将 iOS 应用程序从 Parse.com 移至 Heroku 上的 Parse-Server。这是我在 main.js 云代码文件中的内容:

Parse.Cloud.beforeSave
("Shop", function(request, response)
 {
 var queryConfig,historicOrderVal;

 var queryConfig = new Parse.Query("Configuration");
 queryConfig.find({
                  success: function(resultConf) {
                  .......
                  newShopAnnounce();
                  response.success();
                  },
                  error: function() {
                  var reptMsg="The Configuration-UPDATE procedure failed for some reason.";
                  console.log(reptMsg);
                  response.error(reptMsg);
                  }
                  });
  });


function newShopAnnounce()
{
    var reptMsg="Now inside newShopAnnounce.";
    console.log(reptMsg);
    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.equalTo('deviceType', 'ios');

    Parse.Push.send({
                    where: pushQuery, // Set our Installation query
                    data: {alert: "NEWSHOP"}
                    }, {
                    success: function() {},
                    error: function(error) {
                    throw "Got an error " + error.code + " : " + error.message;
                    }
                    });
}

我主要工作,除了我没有看到任何通知(在 iOS 应用程序中)。 我可以在日志中看到调用了 newShopAnnounce() 函数,但它似乎没有发送任何内容。

如果我将 Parse.Push.send() 调用更改为:

Parse.Push.send({
                where: pushQuery, // Set our Installation query
                data: {alert: "NEWSHOP"}
                }, {
                success: function() {},
                error: function(error) {
                throw "Got an error " + error.code + " : " + error.message;
                },
                useMasterKey: true
                });

我明白了:

app[web.1]: Now inside newShopAnnounce.
app[web.1]: info: beforeSave triggered for Shop for user Xacb6CzuH9:
app[web.1]:   Input: {....}
app[web.1]:   Result: {"object":{....}} className=Shop, triggerType=beforeSave, user=Xacb6CzuH9
app[web.1]: error: Error generating response. ParseError { code: 115, message: 'Missing push configuration' } code=115, message=Missing push configuration
app[web.1]: [object Object]
heroku[router]: at=info method=POST path="/parse/classes/Configuration/XYZABC" host=myapp.herokuapp.com request_id=27558d44-d2f5-4a8a-bfef-b85ea4bff9fa fwd="54.158.219.143" dyno=web.1 connect=0ms service=161ms status=200 bytes=522
2016-11-25T06:43:38.483058+00:00 heroku[router]: at=info method=POST path="/parse/logout" host=myapp.herokuapp.com request_id=123456-7718-4cf9-f54f-123456 fwd="106.130.42.63" dyno=web.1 connect=1ms service=173ms status=200 bytes=483

我错过了什么?

【问题讨论】:

    标签: ios heroku parse-platform push-notification parse-server


    【解决方案1】:

    我认为您的发送方法中缺少useMasterKey: true

    请参阅以下内容以供参考 https://github.com/ParsePlatform/parse-server/issues/401

    您似乎缺少推送配置。请在您的配置中添加以下内容

     push: {
    android: {
      senderId: '', // The Sender ID of GCM
      apiKey: '' // The Server API Key of GCM
    },
    ios: {
      pfx: '', // The filename of private key and certificate in PFX or PKCS12 format from disk  
      passphrase: '', // optional password to your p12
      cert: '', // If not using the .p12 format, the path to the certificate PEM to load from disk
      key: '', // If not using the .p12 format, the path to the private key PEM to load from disk
      bundleId: '', // The bundle identifier associate with your app
      production: false // Specifies which environment to connect to: Production (if true) or Sandbox
    }
    

    }

    例如:

    push: {
        ios: [
            {
                pfx: 'file/***_APNs_Distribution_Certificate.p12', // Dev PFX or P12
                bundleId: 'com.***.***',
                production: true // Dev
            },
            {
                pfx: 'file/***_APNs_Development_Certificate.p12', // Dev PFX or P12
                bundleId: 'com.***.***'',
                production: false // Dev
            }
        ]
    },
    

    也请参考https://github.com/ParsePlatform/parse-server/wiki/Push 了解更多信息。

    【讨论】:

    • 看来你是对的,但我可能错过了更多。尝试了您的建议后,我更新了我的帖子,请看一下。您可能还有更多话要说。
    • 好的,谢谢。我想我必须更新我的 .p12 文件,对吗?
    • @Michel,是的,如果已过期。然后将其包含到您的 heroku 服务器中并添加推送配置的路径。
    • 我已经花了相当长的时间来遵循您的建议以及在您提到的链接中可以找到的内容。但此时它仍然无法正常工作。我在这里发了一个新帖子:stackoverflow.com/questions/40815928/…
    • 你让我走上了正轨。谢谢。我得到了最终的答案,让它发挥作用,我之前评论中提到的帖子。
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 2017-04-29
    • 2019-01-14
    相关资源
    最近更新 更多