且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在适用于 Android 和 iOS 的 Xamarin Cross-Plotform 应用程序中的应用程序图标上显示徽章计数

更新时间:2022-12-22 11:57:50

根据官方文档 ApplicationIconBadgeNumber,在 iOS8+ 上,我们需要注册用户通知才能设置应用程序图标徽章编号:

According to the official documentation ApplicationIconBadgeNumber, On iOS8+ we need to register for user notifications to be able to set the application icon badge number:

//Register this in the Appdelegate
UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

然后您可以使用 CrossBadge.Current.SetBadge(number);

另外如果你想在原生iOS平台上设置徽章,你可以直接尝试UIApplication.SharedApplication.ApplicationIconBadgeNumber = number;.

Moreover if you want to set the badge on the native iOS platform, you can try UIApplication.SharedApplication.ApplicationIconBadgeNumber = number; directly.