I was following this tutorial to implement notifications through FCM. At their Register for remote notifications section there is a code snippet:
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.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 ();
So seems like there are no problem but when I implemented this to my MBB hybrid project the line:
UNUserNotificationCenter.Current.Delegate = this;
gives an error, saying Cannot implicitly convert type 'MyApp.iOS.AppDelegate' to UserNotifications.IUNUserNotificationsCenterDelegate'. An explicit conversion exists
It won't let me compile but if I explicitly cast it into what it wants it also gives error.
Found another example of Xamarin Forms at this post (I translated mostly since I don't know Spanish) and they're doing the same.
What's the correct way to cast register for notifications for Mobile Blazor Bindings project -if this is because I'm using MBB rather than Xamarin Forms?
UNUserNotificationCenter.Current.Delegate = this; gives error of Error CS0266 Cannot implicitly convert type 'Project.iOS.AppDelegate' to 'UserNotifications.IUNUserNotificationCenterDelegate'. An explicit conversion exists (are you missing a cast?)
After some research I found that I didn't include the necessary Interfaces. AppDelegate class should look like this.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
{
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With