В формах xamarin, когда IOS system pu sh оповещение срабатывает после того, как весь пользовательский интерфейс останавливается на iOS 13 и выше - PullRequest
0 голосов
/ 11 марта 2020

В формах xamarin, когда IOS, оповещение системы pu sh срабатывает после того, как весь пользовательский интерфейс останавливается на iOS 13 и выше. Ниже iOS 13 тот же код работает правильно.

Но в ios 13 не может щелкнуть или не выполнить никаких действий. Ниже кода у меня есть интерфейс вызова на моей странице .cs

async void registerforPushNOtitifcationIOS()
        {
            if (Settings.Current.DeviceType.Equals("ios"))
            {

                var push = DependencyService.Get<IPushNotifications>();
                if (push != null)
                {
                     await push.RegisterForNotifications();
                     await vm.CallAuthUserAPI();
                }
            }
        }

В реализации интерфейса я должен написать следующий код:

 public Task<bool> RegisterForNotifications()
 {
   if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
    {
                UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
                     (granted, error) =>
                         {
                               if (granted) {
UIApplication.SharedApplication.RegisterForRemoteNotifications();
                               }

                   });
            }
            else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
                        UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                        new NSSet());

                UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }
            return Task.FromResult(true);
        }

На моей странице AppDelegate.cs вызывается метод делегата удаленного уведомления как показано ниже:

public override void RegisteredForRemoteNotifications(UIApplication app, NSData deviceToken)
  {
     if (ServiceEndpoint.AzureServiceBusUrl == nameof(ServiceEndpoint.AzureServiceBusUrl))
                    return;
      // Get current device token
                var DeviceToken = deviceToken.Description;
                if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
                {
                    byte[] result = new byte[deviceToken.Length];
                    Marshal.Copy(deviceToken.Bytes, result, 0, (int)deviceToken.Length);
                    DeviceToken = BitConverter.ToString(result).Replace("-", "");
                    System.Diagnostics.Debug.WriteLine("Device Token above 13 : ", deviceToken);
                }
                else
                {
                    DeviceToken = deviceToken.Description;
                    DeviceToken = DeviceToken.Trim('<').Trim('>');
                    DeviceToken = DeviceToken.Replace(" ", "");
                    System.Diagnostics.Debug.WriteLine("Device Token below 13: ", deviceToken);
                }



                 // Connection string from your azure dashboard
                var cs = SBConnectionString.CreateListenAccess(
                    new NSUrl(ServiceEndpoint.AzureServiceBusUrl),
                    ServiceEndpoint.AzureKey);


                // Register our info with Azure

                NSSet tags = null;
                var hub = new SBNotificationHub(cs, ServiceEndpoint.AzureHubName);
                hub.RegisterNativeAsync(deviceToken, tags, err =>
                {
                    if (err != null)
                        Console.WriteLine("Error: " + err.Description);
                    else
                        Console.WriteLine("Azzure Notify regi Success");
                });
            }
...