【问题标题】:Can't receive push notification from Parse server and ionic app (ios)无法从 Parse 服务器和 ionic 应用程序 (ios) 接收推送通知
【发布时间】:2017-06-26 02:09:17
【问题描述】:

我遇到了一个我什至不知道是什么问题的问题。

先用ios试试。

我正在从解析服务器开源推送通知。我为推送设置了解析服务器:

"push": {
      "ios":{
         "pfx": "/var/www..../Certificates.p12",
         "passphrase": "...",
         "bundleId": "com.xxxx.testPushNotification",
         "production": false
      }
   }

我正在使用这个插件https://github.com/phonegap-build/PushPlugin。这是我的平台

Installed platforms:
  ios 4.3.1
Available platforms: 
  amazon-fireos ~3.6.3 (deprecated)
  android ~6.0.0
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  osx ~4.0.1
  webos ~3.7.0

cordova 6.4.0

这是 app.js 中的代码

$("#app-status-ul").append('<li>registering ' + device.platform + '</li>');
    pushNotification.register(
    tokenHandler,
    errorHandler,
    {
        "badge":"true",
        "sound":"true",
        "alert":"true",
        "ecb":"onNotificationAPN"
    });
// result contains any message sent from the plugin call
function successHandler (result) {
    alert('result = ' + result);
}
// result contains any error description text returned from the plugin call
function errorHandler (error) {
    alert('error = ' + error);
}
function onNotificationAPN (event) {
  if ( event.alert )
  {
      navigator.notification.alert(event.alert);
  }

  if ( event.sound )
  {
      var snd = new Media(event.sound);
      snd.play();
  }

  if ( event.badge )
  {
      pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
  }
}
  function tokenHandler (result) {
      // Your iOS push server needs to know the token before it can push to this device
      // here is where you might want to send it the token for later use.
      alert('device token = ' + result);
  }
  // fired when push notification is received
  window.onNotification = function (e) {
      navigator.notification.alert('Notification received: ' + JSON.stringify(e));
  }  
  var pushNotification = window.plugins.pushNotification;
  pushNotification.register(successHandler, errorHandler, {"channelName":"xxxx","ecb":"onNotification"});

  function successHandler(result) {
      console.log('registered###' + result.uri);
      // send uri to your notification server
  }
  function errorHandler(error) {
      console.log('error###' + error);
  }

基本上我可以管理服务器端,因为我发送了几条消息但实际上并未发送。

please click to see picture

我设法获得了 .p12 和 .pem,并且应用程序 ID 在应用程序和服务器端之间匹配。

我的问题在哪里?帮助将不胜感激。

【问题讨论】:

    标签: ios cordova ionic-framework push-notification parse-server


    【解决方案1】:

    我自己找到了答案,希望对你有帮助

    在 deviceReady() 中

    if(window.ParsePushPlugin){
      ParsePushPlugin.getInstallationId(function(id) {
         // note that the javascript client has its own installation id,
         // which is different from the device installation id.
          alert("device installationId: " + id);
      }, function(e) {
          alert('error');
      });
    
      ParsePushPlugin.getSubscriptions(function(subscriptions) {
          alert(subscriptions);
      }, function(e) {
          alert('error');
      });
    
      ParsePushPlugin.subscribe('SampleChannel', function(msg) {
          alert('OK');
      }, function(e) {
          alert('error');
      });
    
      ParsePushPlugin.unsubscribe('SampleChannel', function(msg) {
          alert('OK');
      }, function(e) {
          alert('error');
      });
      ParsePushPlugin.on('receivePN', function(pn){
          alert('yo i got this push notification:' + JSON.stringify(pn));
      });
    

    //在config.xml里面

    <preference name="ParseAppId" value="xxxxxx" />
    <preference name="ParseServerUrl" value="http://xxxxx:1389/parse" />
    <preference name="ParseGcmSenderId" value="xxxxxx" />
    <preference name="ParseMultiNotifications" value="true" />
    

    插件:https://github.com/taivo/parse-push-plugin

    注意:在服务器和应用程序之间设置相同的 appId(应用程序包),并确保 p12 和 pem 文件位于应用程序的根文件夹中。

    【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 2016-08-22
    • 1970-01-01
    • 2023-02-18
    • 2020-06-21
    • 2019-12-04
    相关资源
    最近更新 更多