ios 刷新令牌未触发插件.FirebasePushNotification - Xamarin.表单

u5i3ibmn  于 2023-03-09  发布在  iOS
关注(0)|答案(1)|浏览(99)

我正在尝试在我的移动的应用程序中发送远程通知,该应用程序使用Xamarin. Forms构建。我已经在Firebase中进行了所有必要的控制台设置,并上传了google-services.json和googleService-info. plist。通知功能在Xamarin.Forms android上运行良好,但同样的代码在Xamarin forms iOS上不起作用。
我的应用程序xamal.cs:

public partial class App : Application
{
     public App()
     {
            InitializeComponent();
            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) => {
                  string token = p.Token;
                  System.Diagnostics.Debug.WriteLine($"TOKEN REFRESHED: {token}");
                  _ = MyService.UpdateUserDeviceToken(token);
            };
     }
     ...
}

这是我的AppDelegate的存储方式:

namespace MyApp.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());
            FirebasePushNotificationManager.Initialize(options, true);
            return base.FinishedLaunching(app, options);
        }

        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);

        }

        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            completionHandler(UIBackgroundFetchResult.NewData);
        }

        public override void WillEnterForeground(UIApplication uiApplication)
        {
            LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
            base.WillEnterForeground(uiApplication);
        }
    }
}

除此之外,我还在Entitlements.plist和Info.plist中启用了推送通知,在后台模式中启用了远程通知,并添加了FirebaseAppDelegateProxyEnabled
但是,它仍然不会在刷新令牌事件上触发。这个东西在Android上运行得非常好,刷新令牌会被触发。我已经参考了这个金块包插件。PushNotification

vngu2lb8

vngu2lb81#

我发现设置有错误。在提供设置时,我提供了手动设置,但没有手动指出自定义权利。因此,通过在手动设置部分选择自定义权利或选择自动设置以登录并自动执行所有必需的设置,修复了该错误。

相关问题