【问题标题】:Xamarin Firebase Cloud Messaging for iOS (appDelegate) RemoteMessageDelegate error适用于 iOS 的 Xamarin Firebase 云消息传递(appDelegate)RemoteMessageDelegate 错误
【发布时间】:2017-03-17 17:07:25
【问题描述】:

我正在尝试将通知的 iOS 处理程序迁移到 Firebase 服务器。在 appDelegate.cs 文件中,xamarin 网站 (https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging) 上的文档是这样的步骤之一:

// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion (10, 0)) {
    // iOS 10 or later
    var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
    UNUserNotificationCenter.Current.RequestAuthorization (authOptions, (granted, error) => {
        Console.WriteLine (granted);
    });

    // For iOS 10 display notification (sent via APNS)
    UNUserNotificationCenter.Current.Delegate = this;

    // For iOS 10 data message (sent via FCM)
    Messaging.SharedInstance.RemoteMessageDelegate = this;
} 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.... 和 UNUSerNotificationCenter.Current... 接收 appdelegate 工作负载。为了使 appdelegate 实现 Usernotificationcenterdelegate,这是可行的。但是,这不适用于 Firebase 消息委托。 firebase 消息委托无法识别。我已经安装了云消息包 (v1.2.1.1)、analytics (3.6.0)、Core (3.4.5) 和实例 ID (1.0.8)。这些包是通过 Nuget 包管理器安装的。

有人知道为什么找不到 FIRMessagingDelegate,或者这些版本的 iOS 包需要做一些具体的事情吗?

【问题讨论】:

    标签: ios firebase xamarin firebase-cloud-messaging


    【解决方案1】:

    FIRMessagingDelegate 被命名为IMessagingDelegate

    [Protocol (Name = "FIRMessagingDelegate", WrapperType = typeof(MessagingDelegateWrapper)), ProtocolMember (IsRequired = true, IsProperty = false, IsStatic = false, Name = "ApplicationReceivedRemoteMessage", Selector = "applicationReceivedRemoteMessage:", ParameterType = new Type[] {
     typeof(RemoteMessage) }, ParameterByRef = new bool[] { false }), Introduced (PlatformName.iOS, 10, 0, PlatformArchitecture.None, null)]
    public interface IMessagingDelegate : INativeObject, IDisposable
    {
      ~~~
    

    在您的UIApplicationDelegate 上实现IMessagingDelegate

    [Register("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate, IMessagingDelegate
    {
        ~~~~
    
        public void ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage)
        {
           Console.WriteLine(remoteMessage);
        }
    
        ~~~~
    }
    

    【讨论】:

    • 正是我需要知道的!谢谢!显然,“ApplicationReceivedRemoteMessage”函数已在“入门”文档中声明,但在更下方的代码中更加隐蔽。老实说,应该重写以解决这个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 2019-07-12
    • 2016-04-19
    相关资源
    最近更新 更多