gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:11:35 24 4
gpt4 key购买 nike

我正在尝试将通知的 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 消息委托(delegate)。无法识别 firebase 消息委托(delegate)。我已经安装了云消息包 (v1.2.1.1)、分析 (3.6.0)、核心 (3.4.5) 和实例 ID (1.0.8)。这些包是通过 Nuget 包管理器安装的。

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

最佳答案

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);
}

~~~~
}

关于ios - 适用于 iOS 的 Xamarin Firebase 云消息传递(appDelegate)RemoteMessageDelegate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42863377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com