I'm trying to add push notifications in my .NET 8 MAUI application. I was looking at the Microsoft documentation and the function
public override void RegisteredForRemoteNotifications is probably what I need. In the app, I'm calling via HttpClient the Azure Notification Hub` to register the device. In the documentation, Microsoft overrides this function:
public override void RegisteredForRemoteNotifications (
UIApplication application, NSData deviceToken)
{
// Get current device token
var DeviceToken = deviceToken.Description;
if (!string.IsNullOrWhiteSpace(DeviceToken)) {
DeviceToken = DeviceToken.Trim('<').Trim('>');
}
// Get previous device token
var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");
// Has the token changed?
if (string.IsNullOrEmpty(oldDeviceToken) || !oldDeviceToken.Equals(DeviceToken))
{
// TODO: Put your own logic here to notify your server that
// the device token has changed/been created!
}
// Save new device token
NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
}
In the documentation, it is clear that I can have a DeviceToken and then add my custom code to register the device in the Azure Notification Hub. Unfortunately, this override doesn't exist in the AppDelegate in the iOS project.
Where is this function coming from? How can I register my iOS device using HttpClient and then receive the notification?
Update
It says no suitable method found to override.
This is contained in
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate,
IUNUserNotificationCenterDelegate {
// ...
public override void RegisteredForRemoteNotifications(UIApplication application,
NSData deviceToken)
{
// ...
}
