gpt4 book ai didi

c# - 如何在适用于 Android 和 iOS 的 Xamarin 跨平台应用程序中的应用程序图标上显示角标(Badge)计数

转载 作者:可可西里 更新时间:2023-11-01 05:39:51 26 4
gpt4 key购买 nike

我正在尝试在收到通知时在 iOS 应用程序中添加图标角标(Badge)。我有一个 PCL 项目,我已经从 Nuget 安装了 Xam.Plugin.Badge ,所以在我的 AppDelegate.cs 文件中我添加了以下内容iOS 代码行

CrossBadge.Current.SetBadge(number);

但在 Mac 模拟器中运行应用程序时,角标(Badge)未显示在应用程序图标上。请任何人纠正我做错的地方。

最好的问候,斯里尼瓦斯。

最佳答案

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

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

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

在 PCL 中更改应用的角标(Badge)

此外,如果你想在原生iOS平台上设置角标(Badge),你可以直接尝试UIApplication.SharedApplication.ApplicationIconBadgeNumber = number;

关于c# - 如何在适用于 Android 和 iOS 的 Xamarin 跨平台应用程序中的应用程序图标上显示角标(Badge)计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48382594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com