适用于iOS的Xamarin Firebase云消息传递(appDelegate)RemoteMessageDelegate错误

时间:2017-03-17 17:07:25

标签: ios firebase xamarin firebase-cloud-messaging

我正在尝试将通知的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),分析(3.6.0),核心(3.4.5)和实例ID(1.0.8)。这些包是通过Nuget包管理器安装的。

任何人都知道为什么无法找到FIRMessagingDelegate,或者是否需要针对这些版本的iOS软件包进行特定的操作?

1 个答案:

答案 0 :(得分: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
{
  ~~~

IMessagingDelegate上实施UIApplicationDelegate

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate, IMessagingDelegate
{
    ~~~~

    public void ApplicationReceivedRemoteMessage(RemoteMessage remoteMessage)
    {
       Console.WriteLine(remoteMessage);
    }

    ~~~~
}