Finally, I found the solution and I wrote a post to explain all the steps to send and receive push notification from Azure Notification Hub in iOS
Push Notification with Azure Notification Hub and documentation

I'm trying to add push notification in my .NET8
MAUI
application. I was looking at the Microsoft documentation and the function
public override void RegisteredForRemoteNotifications
is probably what I need.
[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
public void RegisteredForRemoteNotifications(UIKit.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.
Developer technologies | .NET | .NET MAUI
2 answers
Sort by: Most helpful
-
-
Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
2024-02-26T04:42:31.25+00:00 Hello,
this override doesn't exist in the
AppDelegate
in theiOS
project.Please try the following in your
AppDelegate
class.[Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")] public void RegisteredForRemoteNotifications(UIKit.UIApplication application, NSData deviceToken) { ... }
Tips:
The doc you mentioned is about Apple Push Notification Gateway Service (APNS) without Azure Notification Hubs, and it's about Xamarin.iOS. You could refer to Send push notifications to Xamarin using Azure Notification Hubs | Microsoft Learn.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.