如何在Android和iOS的Xamarin跨平台应用程序中的App图标上显示徽章计数 [英] How to Show Badge count on App icon in Xamarin Cross-Plotform Application for both Android and iOS

查看:82
本文介绍了如何在Android和iOS的Xamarin跨平台应用程序中的App图标上显示徽章计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在收到通知时在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跨平台应用程序中的App图标上显示徽章计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆