对于静默推送通知,我已实现此方法:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
if([userInfo[@"aps"][@"content-available"] intValue]== 1) //it's the silent notification
{
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
// CASE - 1
if (state == UIApplicationStateBackground )
{
//Badge increment
}
// CASE -2 for foreground
else {
//Badge increment
}
handler(UIBackgroundFetchResultNewData);
return;
}
两种情况
1)我想在用户点击通知时减少徽章数量。(app来到前台)
2)当通知到达时(app在前台),并且在徽章中不采取任何操作。
但对于这两种情况,执行相同的代码。并且徽章减量发生。 (注释为案例-2)。
如何根据这些情况采取行动。