iOS开发--UIApplication(IconBadgeNum)

来源:互联网 发布:qq mac版手机 编辑:程序博客网 时间:2024/06/03 21:54

在iOS7以及以前设置应用图标右上角数字都不需要注册的、iOS8之后都需要注册一下、一般在程序启动之后去注册;代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    [self registerUserNotificationTypeBadge];    return YES;}/** *  注册一下 */- (void)registerUserNotificationTypeBadge{    UIApplication *application = [UIApplication sharedApplication];    /**     UIUserNotificationType 枚举类型     UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received     UIUserNotificationTypeBadge   = 1 << 0, // the application may badge its icon upon a notification being received     UIUserNotificationTypeSound   = 1 << 1, // the application may play a sound upon a notification being received     UIUserNotificationTypeAlert     */    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];    [application registerUserNotificationSettings:setting];}

设置IconBadgeNumber
[UIApplication sharedApplication].applicationIconBadgeNumber = 12;

程序进入之后效果:
这里写图片描述

回到主界面看看效果:
这里写图片描述

0 0
原创粉丝点击