1.p8ファイルをFirebaseコンソール>プロジェクトの設定>Apple アプリの構成 で追加したアプリのAPNs 認証キーのアップロードをクリックします。 キーIDはp8ファイルのAuth_以降の文字列です。
2.AppDelegateに以下のクラスを継承します。 IMessagingDelegate, IUNUserNotificationCenterDelegate
3.以下のコードをAppDelegateに記述します。
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
Console.WriteLine(userInfo);
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
//Messaging.SharedInstance.AppDidReceiveMessage (userInfo);
// Print full message.
Console.WriteLine(userInfo);
HandleMessage(userInfo);
completionHandler(UIBackgroundFetchResult.NewData);
}
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
var userInfo = notification.Request.Content.UserInfo;
Console.WriteLine(userInfo);
completionHandler(UNNotificationPresentationOptions.None);
}
4.Entitlements.plistをダブルクリックし、ページ下部のプッシュ通知をクリックすることでチェックボックスが表示されるので、チェックを入れて有効化します。
これで通知を受け取ることができるはずです。
ありがとうございました。
前回>p8ファイルの作成 https://jp.magicode.io/aoesk/articles/fa0f1f6670894f3088248dff115bbe16