アプリケーションがフォアグラウンドになると、applicationBadgeNumberを0に設定しても、アプリケーションを終了すると、アプリに「1」バッジが残っています、 何か案は?アプリがバックグラウンドになっているときに通知を開くと、何の問題もありません。ローカル通知、applicationIconBadgeNumberは、アプリケーションがフォアグラウンドにあるときに残ります
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"%i", notification.applicationIconBadgeNumber); // Return 1
notification.applicationIconBadgeNumber = 0;
NSLog(@"%i", notification.applicationIconBadgeNumber); // Return 0
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive)
{
// Application was in the background when notification
// was delivered.
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"An item is asking your attention" message:nil delegate:nil
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Show me", nil];
[alert show];
}
}
これはトリックでした。通知バッジとアプリケーションバッジの違いは何ですか? application.applicationIconBadgeNumber = 0; vs notification.applicationIconBadgeNumber = 0; – allaire
正直言って、私は通知でバッジ番号を設定することが何を意味するのか分かりません。これはOSのようなものです。私が知っているのは、アプリケーションのバッジ数をどのように設定するかということだけです。それがうまくいってうれしい! – Rayfleck
通知のバッジ番号は、通知が発生したときにアプリアイコンのバッジが設定される番号です。悲しいことに、それは静的な数字です。 通知が送信された後でこの番号を変更した場合は、何も効果がありません(定期的な通知である場合を除く)。 – AXE