应用程序关闭时更新徽章图标 [英] Update badge icon when app is closed

查看:30
本文介绍了应用程序关闭时更新徽章图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我收到 PN 时,我正在尝试更新我的应用程序的徽章图标(已关闭).

I am trying to update the badge icon for my app(closed) when I received a PN.

我已尝试将代码添加到其中,但当我的应用程序关闭时它不起作用.它在应用程序在前台运行时工作.

I have tried adding the codes into but it's not working when my app is closed. It works when the app is running in the foreground.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

//Accept push notification when app is not open
    if (remoteNotif) {
      [application setApplicationIconBadgeNumber:100];
    return YES;
    }

}
    -(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {

            [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 30];

    }

推荐答案

如果您的应用已关闭或处于后台,推送通知将不会将其唤醒.您需要在服务器端执行此操作,并在通知有效负载中包含您希望在图标上看到的数字:

If you app is closed or in the background, a Push notification won't wake it up. You need to do this server side and include the number you want to see on icon in your notification payload:

{
    "aps" : {
        "alert" : "Your notification message",
        "badge" : 1
    }
}

查看 推送通知编程指南

这篇关于应用程序关闭时更新徽章图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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