简体   繁体   English

从客户端增加徽章数量而不是从有效负载接收计数增加

[英]Increase Badge Count From Client side not from Payload Receive count

I am working on application that receives notification and set application badge. 我正在处理接收通知和设置应用程序徽章的应用程序。
The problem is that when the application is in background state or terminated, the badge count isn't increased. 问题是当应用程序处于后台状态或终止时,徽章计数不会增加。
It remains same. 它保持不变。

While when app is in foreground method calls and badge count increased. 当app处于前台时,方法调用和徽章数量增加。
I already did that thing from server side, 我已经从服务器端那样做了,

but I want to know that Is there any method that execute when app is in background or terminated for increasing application badge number? 但我想知道是否有任何方法在应用程序处于后台时执行或因应用程序徽章编号增加而终止?

I already told you I have done this thing as 我已经告诉过你我做过这件事

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9
    }
}

from server side but what I want is : I dont want to receive that badge count from server payload but I want to increase badge count from my side. 从服务器端,但我想要的是: 我不想从服务器有效负载收到该徽章数,但我想增加我身边的徽章数。

My logic is like that when I receive first notification I saved count in userdeafualts in didReceiveNotification and when I second notification I added count with +1 and when app is in foreground I directly change that badge count as 0 in userdefaults BUT THIS METHOD CANT WORK IN BACKGROUND OR APP TERMINATED 我的逻辑是这样的,当我收到第一个通知时,我在didReceiveNotification中保存了userdeafualts中的计数,当我第二次通知时,我添加了+1计数,当app在前台时,我直接将该徽章计数更改为0在userdefaults中但是这个方法无法工作背景或应用程序终止

SO I WANT TO KNOW IF THERE IS ANY METHOD THAT EXECUTES IN BACKGROUND OR APP IS TERMINATED SO I CAN INCREASE BADGE COUNT 所以我想知道是否有任何方法在背景或应用程序中执行,因此我可以增加BADGE COUNT

If anyone knows please help me do it from my side. 如果有人知道请帮助我从我这边做。

Use application(_:didReceiveRemoteNotification:fetchCompletionHandler:) of UIApplicationDelegate . 使用UIApplicationDelegate application(_:didReceiveRemoteNotification:fetchCompletionHandler:) System wakes up your app, if you enabled the remote notifications background mode. 如果您启用了远程通知后台模式,系统会唤醒您的应用。 For more info check the documentation for this method 有关详细信息,请查看此方法的文档

To receive a push notification when your app is in the background you need to update the Capabilities of your Target in Xcode and add Background Modes...Remote Notifications. 要在应用程序处于后台时接收推送通知,您需要更新Xcode中目标的功能并添加后台模式...远程通知。 You must then add the key content-available to the payload and set to 1. This will trigger application:didReceiveRemoteNotification:fetchCompletionHandler: . 然后,您必须添加content-available用于有效负载的密钥content-available并设置为1.这将触发application:didReceiveRemoteNotification:fetchCompletionHandler: . See the documentation here . 请参阅此处的文档。

When the app is terminated there is nothing you can do. 当应用程序终止时,您无能为力。

如果您要签入AppDelegate.m文件,可以使用一种方法来了解该应用程序是否在后台。

- (void)applicationDidEnterBackground:(UIApplication *)application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM