当应用处于后台/暂停模式时更新徽章图标

时间:2015-03-21 05:48:35

标签: ios ios8 push-notification xcode6 apple-push-notifications

我想在收到通知时更新应用程序徽章图标。它在应用程序运行时工作正常(活动模式),但在应用程序处于挂起/后台模式时尝试设置时遇到问题。想要在不使用徽章的情况下实现同样的目标。在apns词典中的字段。

这就是我在做什么,

-(void) incrementOneBadge{
NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
numberOfBadges +=1;

  [[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];

}

-(void) decrementOneBadge{ NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber;
numberOfBadges -=1;

  [[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
}

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  UIApplicationState state = [application applicationState];
  if (state == UIApplicationStateActive) {

  } 
  else {
    // Push Notification received in the background
    [self incrementOneBadge];

  }

  [self handlePushNotificationsForState:application withDictionary:userInfo];
}

0 个答案:

没有答案
相关问题