我是按照这个教程来的。http:/intown.biz20140411android-notifications。我正在开发一个Node.jsAngularPhoneGapIonic应用,使用的是 node-gcm
来发送通知。
但是我对教程中的一些地方理解起来很麻烦。在代码的最后一部分,即Android应用程序代码中,你可以看到.NET Framework 2.0和.NET Framework 3.0。
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
的安卓设备?
是的,你必须写一个服务来发送注册id到你的服务器。
注册ID不是一个Android设备的ID。 它是 GCM 为设备上的应用程序实例分配的 ID。您的服务器使用该 ID 向特定设备上的应用程序发送消息。
您可以使用像这样的 servicefactory
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中Inject the factoryservice。