Xamarin IOS FCM - DidReceiveRemoteNotification вызывается случайным образом - PullRequest
0 голосов
/ 07 ноября 2019

При обработке push-уведомлений в xamarin IOS с помощью обработчика DidReceiveRemoteNotification он работает случайным образом на переднем и заднем плане.

Иногда я получаю уведомления, а иногда нет.

Мы используем Xamarin.IOS13.4.

Это наш код AppDeletage.cs:

    [Register("AppDelegate")]
    public class AppDelegate : FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            RegistrarNotificacionesRemotas();
            LoadApplication(new App());
            App.ConfigNotificationEvents();

            return base.FinishedLaunching(app, options);
        }

        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
           App.SendRegistrationToServer(deviceToken.ToString(), (int)Plataforma.iOS);
        }

        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {


        }


        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {

        }

        private void RegistrarNotificacionesRemotas()
        {
            Firebase.Core.App.Configure();
            // 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);
            }

            UIApplication.SharedApplication.RegisterForRemoteNotifications();
            Messaging.SharedInstance.Delegate = this;
            Messaging.SharedInstance.ShouldEstablishDirectChannel = true;
        }

    }
}

На переднем плане все работает нормально, но в фоновом режиме никогда не срабатывает методы ReceivedRemoteNotification или DidReceiveRemoteNotification

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...