在应用后台或关闭时推送通知后显示 IconBadgeNumber (Xamarin.iOS)



在我的 Xamarin.iOS 项目中,我使用 Azure 通知中心向我的应用程序发送推送通知。

我可以在课堂上使用此代码控制我的 IconBadgeNumberAppDelegate

var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;

当它们到来时,我可以计算我的推送通知的数量:

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
ProcessNotification(userInfo, false);
UIApplication.SharedApplication.ApplicationIconBadgeNumber = UIApplication.SharedApplication.ApplicationIconBadgeNumber + 1; ;
}

但只有打开我的应用程序,它才会起作用。当我的应用处于背景或关闭状态时,如何计算 IconBadgeNumber 的推送通知?

推送通知的计数取决于您在推送服务中的设置。如

Message message = Message.builder()
.setApnsConfig(ApnsConfig.builder()
.putHeader("apns-priority", "10")
.setAps(Aps.builder()
.setAlert(ApsAlert.builder()
.setTitle("$GOOG up 1.43% on the day")
.setBody("$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.")
.build())
.setBadge(42)
.build())
.build())
.setTopic("industry-tech")
.build();

您可以设置徽章的数量setBadge(xxx)

最新更新