设置APP 在user点击APP icon图标后 badge小红钮不管显示几个 收到多少条notification, 都显示为0- [UIApplication sharedApplication].applicationIconBadgeNumber = 0;;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self resetUserDefault];// Override point for customization after application launch.
/**
* APNS 判断system Version
*/
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f) {
//位移枚举 按位枚举
//配置设置
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]];
//远程
[[UIApplication sharedApplication] registerForRemoteNotifications];
}else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert ];
}
/**
* set badgeNum = 0 once APP icon is clicked by users
*/
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
/*
//判断是否由远程消息通知触发应用程序启动
if (launchOptions) {
//获取应用程序消息通知标记数(即小红圈中的数字)
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
if (badge>0) {
//如果应用程序消息通知标记数(即小红圈中的数字)大于0,清除标记。
badge--;
//清除标记。清除小红圈中数字,小红圈中数字为0,小红圈才会消除。
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;
NSDictionary *pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
//获取推送详情
NSString *pushString = [NSString stringWithFormat:@"%@",[pushInfo objectForKey:@"aps"]];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"finish Loaunch" message:pushString delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil, nil];
[alert show];
}
}
/**
* 注意:app 前台运行时,会调用 remote notification;app后台运行时,点击提醒框,会调用remote notification,点击app 图标,不调用remote notification,没反应;app 没有运行时,点击提醒框,finishLaunching 中,launchOptions 传参,点击app 图标,launchOptions 不传参,不调用remote notification。
*/
*/
return YES;
}
本文介绍如何在iOS应用中,通过设置应用图标徽章数为0来清除未读通知计数,无论有多少通知未读。文章还展示了如何根据不同iOS版本配置远程通知和本地通知设置。
2073

被折叠的 条评论
为什么被折叠?



