如何设置离子推送通知的动作

时间:2016-06-07 14:03:47

标签: android cordova ionic-framework push-notification

我使用离子实现了一个Android应用程序。我想用一些动作来实现推送通知,比如接受和拒绝。 我使用phonegap pluginpush进行推送通知。

enter image description here

但是当我点击它们时没有任何反应。

已发送通知

POST /push/notifications HTTP/1.1
Host: api.ionic.io
Content-Type: application/json
Authorization: Bearer xxxxxxxxxxxxxx


{
    "tokens": ["token1","token2"],
    "profile": "profile",
    "notification": {
        "title": "data updated ",
        "message":"allow sync immediatly",
        "android": {               
                        "data": {
                            "image": "www/img/icon.png",
                            "vibrationPattern": [100, 1000, 500, 500],
                            "notId": 121,
                             "actions": [
                                {  "title": "Approve ", "callback": "accept", "foreground": true},
                                {  "title": "Reject", "callback": "reject", "foreground": true}
                              ]
                        }
                   }
    }

}

的JavaScript

angular.module('app')

  .factory("notificationService", function ($http, $q, $ionicPlatform, baseUrl, $ionicPush, $localStorage, USER) {

    window.approve = function(data){ alert("Approve Triggered");  }   
    window.reject = function(data){ alert("Reject Triggred");  }

    var notification = function () {

      $ionicPlatform.ready(function () {

        $ionicPush.init({
          "debug": true,
          "onNotification": function (notification) {
            alert("notification received");
            var payload = notification.payload;
          },
          "onRegister": function (data) {
            saveGcmToken(USER.parentId(), data);
          },
          "pluginConfig": {
            "android": {
              "badge": true,
              "sound": true,
              "alert": true,
              "icon": "icon",
              'forceShow'  : true,
              //"iconColor": "#948438"
            },
            "ios": {
              "badge": true,
              "sound": true,
              "forceShow"  : true,
              "alert": true

            }
          }
        });
        $ionicPush.register({
          canShowAlert: true,
          canSetBadge: true,
          canPlaySound: true,
          canRunActionsOnWake: true,
        });
      });
    }

    function saveGcmToken(parentId, token) {

      var data = {};

      angular.extend(data, {
        id: parentId,
        name: token._token
      });

      $http({
        method: 'PUT',
        contentType: 'application/json',
        data: data,
        url: baseUrl + "/add-app-token"
      }).success(function (response) {
        alert("response from notification service" + JSON.stringify(response));
      }).error(function (response) {
        alert("Error " + JSON.stringify(response));
      });

    }

    return {
      notification: notification
    }

  })

1 个答案:

答案 0 :(得分:1)

尝试更新您的提醒功能。

"onNotification": function (notification) {
            alert('message = '+notification.message+' title = '+notification.title + ' actions = '+notification.android.data.actions+ ' notId = '+notification.android.data.notId);
          }

详情请访问:http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/

https://www.npmjs.com/package/phonegap-plugin-push-pgb

相关问题