收到推送 → 圖標右上角紅點數字 +1;用戶打開 App → 數字歸零。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 註冊遠程通知...
return YES;
}
// App 進入前台/啟動時清零
- (void)applicationWillEnterForeground:(UIApplication *)application {
application.applicationIconBadgeNumber = 0;
}
// 或在具體 ViewController viewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
{
"aps": {
"alert": "新消息",
"badge": 5, // 服務端指定具體數字
"sound": "default"
}
}