从客户端增加徽章数量而不是从有效负载接收计数增加 [英] Increase Badge Count From Client side not from Payload Receive count

查看:107
本文介绍了从客户端增加徽章数量而不是从有效负载接收计数增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理接收通知和设置应用程序徽章的应用程序。
问题是当应用程序处于后台状态或终止时,徽章计数不会增加。
它保持不变。

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.
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
    }
}

从服务器端但我想要的是:我不想从服务器有效负载中获得该徽章数,但我想从我这边增加徽章数。

我的当我收到第一个通知时,逻辑就像那样ved在didReceiveNotification中的userdeafualts中计数,当我第二次通知时,我添加了+1计数,当app在前台时,我直接将该徽章计数更改为0在userdefaults中但该方法无法在后台或应用程序终止中

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

所以我想知道是否有任何方法在背景或应用程序中执行,因此我可以增加BADGE COUNT

如果有人知道请帮助我从我这边做。

If anyone knows please help me do it from my side.

推荐答案

接收推送通知当您的应用程序在后台时,您需要更新Xcode中目标的功能并添加后台模式...远程通知。然后,您必须将密钥 content-available 添加到有效负载并设置为1.这将触发应用程序:didReceiveRemoteNotification:fetchCompletionHandler:。请参阅此处文档。

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. You must then add the key content-available to the payload and set to 1. This will trigger application:didReceiveRemoteNotification:fetchCompletionHandler:. See the documentation here.

当应用程序终止时,你无能为力。

When the app is terminated there is nothing you can do.

这篇关于从客户端增加徽章数量而不是从有效负载接收计数增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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