Androidのプッシュ通知にMicrosoft azure通知ハブを使用しています。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"
}-
}
通知ハブで行った設定:
- 「Google クラウド メッセージング設定」に Google API キーを追加します。
この問題を解決するために私を導いてください。