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

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

问题描述

我试图更新我的应用程序徽章图标(关闭)时,我收到一个PN。

我曾尝试加入codeS进入,但是当我的应用程序关闭时它不工作。当应用程序在前台运行它的工作原理。

   - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
{
       *的NSDictionary = remoteNotif [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];//接受推送通知的应用程序时未打开
    如果(remoteNotif){
      [应用setApplicationIconBadgeNumber:100];
    返回YES;
    }}
     - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO
    {            [UIApplication的sharedApplication] setApplicationIconBadgeNumber:30];    }


解决方案

如果您的应用程序被关闭或在后台推送通知不会唤醒它。你需要做服务器端,包括你想看到的图标在您的通知有效载荷数:

  {
    APS:{
        提醒:您的通知消息,
        徽章:1
    }
}

看一看在<一个苹果文档href=\"http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html\"相对=nofollow>推送通知编程指南

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

Have a look at the Apple doc on Push Notification programming guide

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

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