Skip to content

Instantly share code, notes, and snippets.

@ochim
Last active April 28, 2016 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochim/ebbd87b4411da3e74f42261326fc3a3c to your computer and use it in GitHub Desktop.
Save ochim/ebbd87b4411da3e74f42261326fc3a3c to your computer and use it in GitHub Desktop.
[iOS]アプリアイコンのバッジを更新する

スニペット 抜粋先

- (void)updateIconBadgeNumber:(NSInteger)iconBadgeNumber {
    UIApplication *application = [UIApplication sharedApplication];
    if (floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_8_0) {
        // iOS8 and later
        if ([application currentUserNotificationSettings].types & UIUserNotificationTypeBadge) {
            /*
             バッチの更新処理
             iOS8系の場合は[[UIApplication sharedApplication] currentUserNotificationSettings]で
             更新可能か判断する必要がある
             */
            application.applicationIconBadgeNumber = iconBadgeNumber;
        }
    }
    else {
        // under iOS7
        application.applicationIconBadgeNumber = iconBadgeNumber;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment