1.Firebaseコンソールにプロジェクトを追加します。(バンドル識別子を入力してください。)
追加する際、「GoogleService-Info.plist」のダウンロードをダウンロードします。
2.「GoogleService-Info.plist」をiOSのプロジェクトに追加し、ビルドアクションを「BundleResource」に設定します。
3.Nugetパッケージインストールより、Xamarin.Firebase.iOS.CloudMessagingをインストールします。
4.AppDelegateのFinishedLunchingに Firebase.Core.App.Configure(); を追記します。
5.AppDelegateに任意のクラスを追加し、以下のコードを追加します。
private void InitFCM()
{
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
Console.WriteLine(granted);
});
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
Messaging.SharedInstance.Delegate = this;
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}