【问题标题】:Xamarin Android iOS FirebasePushNotificationPlugin not receive message but token recevesXamarin Android iOS FirebasePushNotificationPlugin 未收到消息但收到令牌
【发布时间】:2020-06-20 06:42:55
【问题描述】:

我正在将 xamarin iOS FirebasePushNotificationPlugin 用于云消息,但我正在接收令牌但我无法收到任何通知。 CrossFirebasePushNotification.Current.OnNotificationReceived 甚至没有开火。

这就是我的 appDelegate 的样子。

using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using Plugin.FirebasePushNotification;
using UIKit;

namespace onlinefirebase.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());
            FirebasePushNotificationManager.Initialize(options, true);
            FirebasePushNotificationManager.CurrentNotificationPresentationOption =
         UserNotifications.UNNotificationPresentationOptions.Alert |
         UserNotifications.UNNotificationPresentationOptions.Badge;
            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);

        }
        // To receive notifications in foregroung on iOS 9 and below.
        // To receive notifications in background in any iOS version
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            // If you are receiving a notification message while your app is in the background,
            // this callback will not be fired 'till the user taps on the notification launching the application.

            // If you disable method swizzling, you'll need to call this method. 
            // This lets FCM track message delivery and analytics, which is performed
            // automatically with method swizzling enabled.
            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            // Do your magic to handle the notification data
            System.Console.WriteLine(userInfo);

            completionHandler(UIBackgroundFetchResult.NewData);
        }
    }
}

这是我收到通知的方式

using System;
using Plugin.FirebasePushNotification;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace onlinefirebase
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new MainPage();


            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}");
            };

            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Received");
            };


        }

        protected override void OnStart()
        {
        }

        protected override void OnSleep()
        {
        }

        protected override void OnResume()
        {
        }
    }
}

我已经验证了

。启用后台模式 -> 远程通知 . Info.plist -> “FirebaseAppDelegateProxyEnabled”布尔值 -> 否

我已成功获取令牌,但收不到通知。

【问题讨论】:

  • 您是否将 GoogleService-Info.plist 添加到 iOS 项目并确保构建操作是 BundleResource。在应用的 Info.plist 文件中添加 FirebaseAppDelegateProxyEnabled 并设置为 No。

标签: c# xamarin xamarin.forms xamarin.ios firebase-cloud-messaging


【解决方案1】:

问题是基于苹果密钥,苹果密钥应该上传到firebase云面板,它会工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 2013-08-28
    • 2020-01-14
    • 2011-05-06
    相关资源
    最近更新 更多