首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Node.js/PhoneGap/Ionic的Android推送通知

使用Node.js/PhoneGap/Ionic的Android推送通知
EN

Stack Overflow用户
提问于 2014-06-09 19:54:13
回答 2查看 2.9K关注 0票数 0

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

但我在理解教程的某些部分时遇到了问题。在代码的最后部分,Android应用程序代码,您可以看到:

代码语言:javascript
复制
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吗?

EN

回答 2

Stack Overflow用户

发布于 2014-06-09 20:29:22

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

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

票数 0
EN

Stack Overflow用户

发布于 2014-06-18 14:55:16

您可以像这样使用服务/工厂

代码语言:javascript
复制
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中注入工厂/服务

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24119751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档