为了账号安全,请及时绑定邮箱和手机立即绑定

C# Xamarin iOS RegisteredForRemoteNotifications

C# Xamarin iOS RegisteredForRemoteNotifications

C#
凤凰求蛊 2021-10-24 19:29:45
你好 !我正在尝试使用Azure Notification Hub在我的 xamarin iOS 应用程序上添加通知。按照本教程(https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started)之后,我遇到了一个问题在我的 appdelegate.cs 文件中:RegisteredForRemoteNotifications方法从未被触发,因此我的应用程序无法在我的集线器上注册。通知的所有权限都已完成,设置也是如此,我做了很多研究,但没有一个解决方案适用于我的情况。我已经尝试过Xamarin.iOS RegisteredForRemoteNotifications not called在我的 FinishedLaunching 方法中,我有:if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)){        UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (granted, error) =>         {            if (granted)            {                    InvokeOnMainThread(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);}我的RegisteredForRemoteNotifications方法是:public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)    {            Hub = new SBNotificationHub(Constants.ListenConnectionString, Constants.NotificationHubPath);            Hub.UnregisterAllAsync(deviceToken, (error) => {                if (error != null)                {                        Console.WriteLine("Error calling Unregister: {0}", error.ToString());                        return;                }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 167 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信