我正在开发一个Node.js/Angular/PhoneGap/ http://intown.biz/2014/04/11/android-notifications/应用程序,使用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吗?
发布于 2014-06-09 20:29:22
是的,您必须编写一个将注册id发送到您的服务器的服务。
注册id不是Android设备的id。它是GCM为设备上的应用程序实例分配的id。您的服务器使用该id向特定设备上的应用程序发送消息。
发布于 2014-06-18 14:55:16
您可以像这样使用服务/工厂
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中注入工厂/服务
https://stackoverflow.com/questions/24119751
复制相似问题