【问题标题】:Android push notifications using Node.js/PhoneGap/Ionic使用 Node.js/PhoneGap/Ionic 的 Android 推送通知
【发布时间】:2014-06-09 11:54:13
【问题描述】:

我正在关注本教程:http://intown.biz/2014/04/11/android-notifications/ 我正在开发一个 Node.js/Angular/PhoneGap/Ionic 应用程序,使用 node-gcm 发送通知。

但我无法理解本教程的某些部分。在代码的最后一部分,Android应用程序代码,你可以看到:

registerID : function (id) {
            //Insert code here to store the user's ID on your notification server.
            //You'll probably have a web service (wrapped in an Angular service of course) set up for this. 
            //For example:
            MyService.registerNotificationID(id).then(function(response){
                if (response.data.Result) {
                    console.info('NOTIFY  Registration succeeded');
                } else {
                    console.error('NOTIFY  Registration failed');
                }
            });

所以我必须编写一个服务(这里称为MyService)来获取用户的ID,对吧?

问题是:我什么都不懂,我什至不确定我们在这里谈论的是哪个ID。那是安卓设备的ID吗?

【问题讨论】:

    标签: android angularjs cordova push-notification ionic-framework


    【解决方案1】:

    是的,您必须编写一个将注册 ID 发送到您的服务器的服务。

    注册 ID 不是 Android 设备的 ID。这是 GCM 为设备上的应用程序实例分配的 id。您的服务器使用该 ID 向特定设备上的应用程序发送消息。

    【讨论】:

      【解决方案2】:

      你可以使用这样的服务/工厂

      app.factory('registerId', ['$http',function($http){
      return {
        registerNotificationID: function(id){
            $http
                .post(serverurl+'register-device',{id:id, platform:'android'})//TODO: Change it for Each Platform before building.
                .success(function(res){
                    console.log(res)
                })
                .error(function(e){
                    console.error(e.message)
                })
            }
            }
      }
      

      这应该向 /register-device/ 上的服务器发送一个 POST 请求,您可以从那里处理它,并确保在 DI 中注入工厂/服务

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-17
        相关资源
        最近更新 更多