4

Web ビュー ホスト (Phonegap / Intel XDK) で実行されている html/javascript コードから動作する Azure Notification Hub に登録しようとしています。利用可能なクライアント ライブラリがないため、REST API (ドキュメント: ) を使用してみます。

次の Javascript コードがあります。

function registerWithAzureNotificationHub()
{
    var sas = "Endpoint=sb://eventpusher-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=69XuYoluyBKl6JkkN03Z1oNC7cFSZ4Ku0ZWmPuWoJzs=";
    var data = '<?xml version="1.0" encoding="utf-8"?>\
    <entry xmlns="http://www.w3.org/2005/Atom">\
        <content type="application/xml">\
        <MpnsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">\
        <Tags>myTag, myOtherTag</Tags>\
        <ChannelUri>https://eventpusher-ns.servicebus.windows.net/eventpusher</ChannelUri>\
        </MpnsRegistrationDescription>\
        </content>\
    </entry>';
    if (AppMobi.iswp8) {
        window.alert("IS WP8");
    }
    else
    {
        window.alert("IS NOT WP8");
    }

    $.ajax({
        type:"POST",
        url: "https://eventpusher-ns.servicebus.windows.net/EVENTPUSHER/registrations/?api-version=2013-08",
        contentType: "application/atom+xml;type=entry;charset=utf-8",
        headers: {
            "Authorization": sas,
            "x-ms-version": "2013-08"
        },
        dataType: "xml",
        data: data,
        success: function(d) { window.alert("SUCCESS!"); },
        error: function(msg) { window.alert("FAILURE:" + JSON.stringify(msg)); }
    });
    window.alert("SENT!");
}

上記の場合、WP8 デバイスで実行されるコードで Intel XDK を使用するため、MPNS (Microsoft Push Notification Service) に登録します。

上記のコードは失敗し、エラーの原因に関する説明情報なしで戻ります。

質問:

  1. REST サービスを使用して JavaScript コードから Azure Notification Hub にモバイル デバイスを登録することはできますか?
  2. 上記のコードで何が間違っている可能性がありますか? ChannelUri は正しい Uri ですか?
4

2 に答える 2

1

サーバー側のスニペットを投稿して、トークンを使用してデバイスをハブに登録し、ここで通知を送信できるようにしました。

サーバー側から Azure Notification Hub にデバイスを登録する方法 (NodeJS SDK を使用) ?

Ionic で ngCordova と PushPlugin を使用したクライアント側のコードもあります。見たい人がいたら教えてください。

于 2015-01-27T21:13:34.090 に答える