【问题标题】:How to reset the notification badge number in objective c?如何重置目标c中的通知徽章编号?
【发布时间】:2017-07-18 12:30:34
【问题描述】:

打开上一个通知后,我无法为下一个通知重置通知徽章编号。

【问题讨论】:

标签: ios objective-c iphone apple-push-notifications uilocalnotification


【解决方案1】:

把这段代码写在

-(void)applicationWillEnterForeground:(UIApplication *)application {

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
 }

【讨论】:

    【解决方案2】:

    在它调用之前注册通知

    UIUserNotificationSettings * notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    

    【讨论】:

      【解决方案3】:

      您可以从应用程序本身设置徽章编号,如下所示:

      [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
      

      通过将值设置为 0,您正在重置徽章编号

      要通过推送更新徽章编号,您需要在有效负载中包含以下内容:

      "badge" : 0
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-19
        • 1970-01-01
        • 2020-04-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多