Node.js 在Ionic中使用ngCordova和PushPlugin的azure通知中心客户端代码

Node.js 在Ionic中使用ngCordova和PushPlugin的azure通知中心客户端代码,node.js,azure,push-notification,ionic,cordova-plugins,Node.js,Azure,Push Notification,Ionic,Cordova Plugins,对于爱奥尼亚应用程序,哪一个插件适合用于Azure通知中心? Phonegap/Cordova中有许多用于推送通知的插件,其中一些已被弃用。 请提供一些有关ionic客户端实现Azure notification hub和node.js服务器端实现的代码片段的参考链接。在我的测试ionic项目中,我使用了位于的移动服务插件库和位于的PushPlugin 以下是集成GCM的代码片段: 初始移动服务客户端和GCM配置: /**** Mobile service configs

对于爱奥尼亚应用程序,哪一个插件适合用于Azure通知中心? Phonegap/Cordova中有许多用于推送通知的插件,其中一些已被弃用。
请提供一些有关ionic客户端实现Azure notification hub和node.js服务器端实现的代码片段的参考链接。

在我的测试ionic项目中,我使用了位于的移动服务插件库和位于的PushPlugin

以下是集成GCM的代码片段:

初始移动服务客户端和GCM配置:

    /****
    Mobile service configs
    ****/
    var mobileServiceClient;
    var mobileServiceUrl = 'https://<your_mobile_service_name>.azure-mobile.net/';
    var mobileSerivceKey = '<your service key>';

    /****
    Notification hubs configs
    *****/
    var GCM_SENDER_ID = 'gcm_sender_id_number'; // Replace with your own ID.
    var androidConfig = {
        "senderID": GCM_SENDER_ID,
      };
有关在Cordova应用程序中集成Azure通知中心的更多信息,请参阅

angular.module('myapp', ['ionic','ngCordova'])
.run(function($ionicPlatform,$rootScope,$cordovaPush) {
  $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

    //init mobileServiceClient
    mobileServiceClient = new WindowsAzure.MobileServiceClient(mobileServiceUrl,mobileSerivceKey);
    //register notification push
    console.log("======mobileServiceClient inited going on ======");
    $cordovaPush.register(androidConfig).then(function(result) {
      // Success
      console.log("=============register finished========");
    }, function(err) {
      // Error
    })
    $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
      switch(notification.event) {
        case 'registered':
          if (notification.regid.length > 0 ) {
            $rootScope.GCM_status = true;
            alert('registration ID = ' + notification.regid);
              //register to Azure Mobile Service
            if (mobileServiceClient) {
              // Template registration.
              var template = '{ "data" : {"message":"$(message)"}}';
              // Register for notifications.
              mobileServiceClient.push.gcm.registerTemplate(notification.regid,
                "myTemplate", template, null)
              .done(function () {
                  $rootScope.Azure_Push_status = true;
                  alert('Registered template with Azure!');
              });
              // .fail(function (error) {
              //     alert('Failed registering with Azure: ' + error);
              // });
            }
          }
          break;

        case 'message':
          // this is the actual push notification. its format depends on the data model from the push server
          alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
          break;

        case 'error':
          alert('GCM error = ' + notification.msg);
          break;

        default:
          alert('An unknown GCM event has occurred');
          break;
      }
    });
    // WARNING: dangerous to unregister (results in loss of tokenID)
    $cordovaPush.unregister().then(function(result) {
      // Success!
    }, function(err) {
      // Error
    })

  });
})