Xamarin 为iOS Mobile Blazor绑定将委托对象正确分配给UnuseNotificationCenter对象
我正在跟踪通过FCM实现通知。在他们的部分有一个代码片段: Project.iOS/AppDelegate.cs:Xamarin 为iOS Mobile Blazor绑定将委托对象正确分配给UnuseNotificationCenter对象,xamarin,xamarin.forms,xamarin.ios,Xamarin,Xamarin.forms,Xamarin.ios,我正在跟踪通过FCM实现通知。在他们的部分有一个代码片段: Project.iOS/AppDelegate.cs: // Register your app for remote notifications. if (UIDevice.CurrentDevice.CheckSystemVersion (10, 0)) { // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter
// Register your app for remote notifications.
if (UIDevice.CurrentDevice.CheckSystemVersion (10, 0)) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization (authOptions, (granted, error) => {
Console.WriteLine (granted);
});
} 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 ();
因此,似乎没有问题,但当我将此应用于我的MBB混合动力项目时,生产线:
UNUserNotificationCenter.Current.Delegate=this代码>
给出错误,说明无法将类型“MyApp.iOS.AppDelegate”隐式转换为UserNotifications.IUNUserNotificationsCenterDelegate”。存在显式转换
它不允许我编译,但如果我显式地将它转换为它想要的内容,它也会给出错误
发现了许多Xamarin形式(我主要翻译,因为我不懂西班牙语),他们也在做同样的事情
如果这是因为我使用的是MBB而不是Xamarin表单,那么为Mobile Blazor绑定项目强制转换通知注册的正确方法是什么
复制步骤
创建混合移动Blazor绑定项目(预览5)
在Project.iOS/AppDelegate.cs中,添加UNUserNotificationCenter.Current.Delegate=this代码>给出错误错误CS0266无法将类型“Project.iOS.AppDelegate”隐式转换为“UserNotifications.IUNUserNotificationCenterDelegate”。存在显式转换(是否缺少转换?
如果应用了显式强制转换,也会出现错误,表示无法转换
预期行为
- 成功接收通知
实际行为
经过一些研究,我发现我没有包括必要的接口<代码>AppDelegate
类应如下所示
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
{
//...
}
这对我很有帮助,但我仍然无法收到通知。你有没有在GitHub上发布的解决方案或者其他可以帮助我的东西?