2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mobile Apps以外のAzure App ServiceでNotification hubsを構成

2
Posted at

概要

Azure App Serviceで.NETバックエンドを構成し、Notification hubsを紐づけてプッシュ通知を実装する時に、バックエンドがクイックスタートで構成されている状態ではない場合、
Xamarin.Forms アプリにプッシュ通知を追加する
に記載されている通り、サーバ側に拡張をインストールする必要がありますので、その過程のメモです。

構成

クライアント

Xamarin.formsでGcmServiceを作成
MobileServiceClientを使ってAzureNotificationHubsへアプリを登録する

サーバ

既存のAPI Appsにプッシュ通知の機能を追加

サーバ側のプッシュ通知の構成

上記リンク先の前提に以下のように記載されています。

ダウンロードしたクイック スタートのサーバー プロジェクトを使用しない場合は、プッシュ通知拡張機能パッケージをプロジェクトに追加する必要があります。

Web APIの場合、WebApiConfig.csにRegisterメソッドがあると思いますので、そこに以下を追記します。

WebApiConfig.cs
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API の構成とサービス
            new MobileAppConfiguration()
                .AddPushNotifications()
                .ApplyTo(config);

            //(以下省略)
        }
    }

ただし、デフォルトの状態ですと、AddPushNotificationsが見つからないエラーが出ると思いますので、NuGetからMicrosoft.Azure.Mobile.Server.Notificationsをインストールします。

image

この設定をしていない場合、クライアント側でGcmServiceBaseを継承したクラスから、アプリケーションをNotificationHubsに登録する時に、

『The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.』

というエラーメッセージが吐かれます。

詳しくエラーの内容を調べてみると、MobileServiceClient.GetPush();で取得したPushオブジェクトを通してRegisterAsyncメソッドでアプリケーションを登録すると、
Pushオブジェクトの取得元であるMobileServiceClientを初期化する際に設定されたURLを基として、
/push/installations/{PushオブジェクトのInstallationId}
へアクセスしているようです。
上記設定をしていないと、このURLの受け皿が構成されなくなるため、先のような404エラーになるということのようです。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?