且构网

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

增加推送通知徽章iPhone

更新时间:2023-02-27 08:56:20

通常在所有应用中未读通知计数在服务器中维护。当服务器向特定设备令牌发送推送通知时,他们会发送徽章计数以及有效负载。一旦设备被通知并且您的应用程序处于后台(或被杀死),操作系统会自动将徽章计数更新为您的应用程序图标。如果您的应用程序是否正在运行,您将收到

Usually in all apps the unread notification counts are maintained in the server. When the server sends a push notification to a particular device token they send the badge count along with the payload. Once the device is notified and your app is in background(or killed) the OS automatically update the badge count to your app icon. In case whether you have your app running, you will get notified in the

application:didReceiveRemoteNotification:

委托,因此您可以从(NSDictionary *)userInfo接收徽章计数。因此,您可以使用函数更新应用程序图标徽章计数

delegate and thus you are able to receive the badge count from the (NSDictionary *)userInfo. And thus you are able to update the app icon badge count using the function

[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];

认为这可以帮到你。