Ionic.cloud的离子推送通知

时间:2017-02-02 15:50:31

标签: android angularjs ionic-framework push-notification google-cloud-messaging

我尝试使用官方网站(https://docs.ionic.io/services/push/)的文档来实现Ionic(1)的推送通知服务,但我不知道如何检索,注册和保存我的Ionic App上的令牌。 你能救我吗?

1 个答案:

答案 0 :(得分:0)

我认为您已安装了phonegap-plugin-push插件并使用了正确的配置,并将您的应用程序注册到 Ionic.io平台以及正确的配置(如官方文档中所述)。

所以,在你的app.js中,你可以这样写:

    /* PUSH */
    //If cordova is installed 
    if(window.cordova){
       var push = new Ionic.Push({
          "debug": false,
          "onNotification": function(notification) {
             //Do something when you receive a notification
             console.log(notification);
          }
       });

       var callback = function(pushToken) {
          //Save the token specified to the device 
          //this token is saved in the Ionic.io database
          push.saveToken(pushToken.token);
       }

       //register you device to your app notification system
       push.register(callback);
   }

然后 Ionic.io平台可让您轻松向所有已注册的设备发送通知。

The Ionic.io push interface