如何在适用于 Android 和 iOS 的 Xamarin Cross-Plotform 应用程序中的应用程序图标上显示徽章计数 [英] How to Show Badge count on App icon in Xamarin Cross-Plotform Application for both Android and iOS
问题描述
我正在尝试在收到通知时在 iOS 应用程序中添加图标徽章.我有一个 PCL 项目,并且我已经从 Nuget 安装了 Xam.Plugin.Badge
,所以在我的 AppDelegate.cs
文件中我添加了以下内容iOS 代码行
I am trying to add the icon badge in iOS application when a notification is received.
I have a PCL Project, And i have installed Xam.Plugin.Badge
from Nuget , so in my AppDelegate.cs
file i have added following line of code for iOS
CrossBadge.Current.SetBadge(number);
但在 Mac 模拟器中运行应用程序时,应用程序图标上未显示徽章.任何人都可以纠正我做错的地方.
But Badge is not showing on App icon when running the app in Mac simulator. Can any one correct me where i am doing wrong please.
最好的问候,斯里尼瓦斯.
Best regards, Srinivas.
推荐答案
根据官方文档 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.
这篇关于如何在适用于 Android 和 iOS 的 Xamarin Cross-Plotform 应用程序中的应用程序图标上显示徽章计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!