3

我正在使用 Microsoft azure 通知中心在 android 中推送通知。我能够通过 nodejs 服务器代码发送通知。设备从 nodejs 服务器获取通知。

问题:-但是当我使用通知中心时,即使通知中心返回成功代码,通知也永远不会到达设备。

我为通知中心遵循的程序。

步骤-1:- 将 gcmTokenId 注册到我在第一次注册时从我的设备获得的通知中心。

notificationHubService.gcm.createNativeRegistration(gcmToken, tags, function(error){    
          if(error)
          {
            res.type('application/json'); // set content-type
            res.send(error); // send text response
          }
          else
          {
            res.type('application/json'); // set content-type
            res.send('Registered Successfully!'); // send text response
          }
        });

以下是注册详情:-

{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj"
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}

步骤-2:- 使用以下功能向集线器发送通知。

notificationHubService.gcm.send(
        null,
        {
            data: { message: 'Here is a message' }
        },
        function (error,response) {
            if (!error) {
                //message send successfully
                res.type('application/json'); // set content-type
        res.send(response);
            }
        });

以下是我从通知中心获得的响应代码。

{
isSuccessful: true
statusCode: 201
body: ""
headers: {
transfer-encoding: "chunked"
content-type: "application/xml; charset=utf-8"
server: "Microsoft-HTTPAPI/2.0"
date: "Tue, 10 Jun 2014 07:07:32 GMT"
}-
}

我在通知中心所做的设置:

  1. 我在“谷歌云消息设置”中添加了谷歌 API 密钥。

请指导我解决这个问题。

4

1 回答 1

0

看来,当您注册时,您提供了“raj”作为标签。

{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj" <<== HERE
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}

标签就像订阅主题——它是一个过滤器。

您似乎正在使用 Node.js NotificationHubService。

请参阅http://dl.windowsazure.com/nodedocs/GcmService.html。第一个参数是tags,但在您的代码中,您提供了一个null

notificationHubService.gcm.send(
    null,   // <-- HERE
    {
        data: { message: 'Here is a message' }
    },

由于null与标签“raj”不匹配,因此通知中心不会将此消息传递到任何注册为仅侦听具有标签“raj”的消息的设备。

您应该在方法调用中将标记设置为“raj” send(),或者从方法调用中删除该标记createNativeRegistration()

于 2014-07-03T01:35:05.010 回答