【问题标题】:Notification Message is not received to Android device from Azure Notification HubAndroid 设备未从 Azure 通知中心收到通知消息
【发布时间】:2014-07-30 20:37:12
【问题描述】:

我正在使用 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. 我在“谷歌云消息设置”中添加了 google api 密钥。

请指导我解决这个问题。

【问题讨论】:

    标签: azure push-notification google-cloud-messaging android-notifications azure-notificationhub


    【解决方案1】:

    您注册时似乎提供了“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”的消息的设备。

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

    【讨论】:

    • null 表示该平台类型的所有目标,不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多