简体   繁体   English

不显示应用程序图标徽章

[英]Application icon badge is not displayed

I set app icon badge using 我使用设置应用程序图标徽章

[UIApplication sharedApplication].applicationIconBadgeNumber = ...;

I change its value on multiples classes. 我在倍数类上改变它的值。 In one of the classes I ma having issue that 在其中一个类中我有问题

NSLog(@"App icon badge : %d", [UIApplication sharedApplication].applicationIconBadgeNumber);

prints some value.eg 4 . 打印一些值.eg 4 But if I put app in background then there is no badge on icon. 但是,如果我将应用程序放在后台,那么图标上没有徽章。 It should display badge 4 . 它应该显示徽章4

I also change badge value in another class. 我还在另一个班级更改徽章价值。 In that it sets correct value and putting app in background shows correct value. 在它设置正确的值,并将应用程序放在后台显示正确的值。

What happens is I am in controller, in which setting of badge value works, and log current badge value then it gives the correct value and putting app in background also shows correct value. 发生的事情是我在控制器中,徽章值的设置工作,并记录当前徽章值,然后它给出正确的值,并将应用程序放在后台也显示正确的值。 But then if go to another controller, in which settings of badge is not working, and log badge value then it always prints 0. 但是如果转到另一个控制器,徽章的设置不起作用,并且记录徽章值,那么它总是打印0。

set your Badge value in this method :- 在此方法中设置您的徽章值: -

- (void)applicationDidBecomeActive:(UIApplication *)application 

                       **OR** 

- (void)applicationWillEnterForeground:(UIApplication *)application

You have to set badge value in appdelegate's different method like below: 您必须在appdelegate的不同方法中设置徽章值,如下所示:

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

I solved it. 我解决了 It was due to below code of parse. 这是由于下面的解析代码。

PFInstallation * currentInstallation = [PFInstallation currentInstallation];
currentInstallation.badge = 0;
[currentInstallation saveEventually:^(BOOL succeeded, NSError *error) {
    if (error)
    {
        ALog(@"Parse error in setting badge on installation object. Error : %@", error);
    }
}];

After below line it was setting app icon badge to 0. 在下面的行之后,它将app图标徽章设置为0。

currentInstallation.badge = 0;

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

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