4

I am developing application that would receive push notifications from server. while sending push notifcation from server you specify the badge number to show on application icon. Now this mean you have to keep track of badge count on server. this don't seems like a good methodology. is there any good alternative for this so i don't need to keep track of badge number on server.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
waseemwk
  • 1,499
  • 3
  • 15
  • 44

1 Answers1

3

When your app isn't in the foreground, you can't do squat about the badge number. Entirely controlled from the server.

When your app IS in the foreground, however, setting the badge can be done from within the app based on any logic that you choose. You can set the badge using:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:someNumber];

The fact that the badge number is generally managed server-side reflects on the fact that the majority of iPhone apps are just front-ends for large (and I do mean LARGE) bodies of back-end logic, knowledge and data. In addition, since a platform's iPhone app is usually just one of many front-ends, replicating actual business logic in a front-end is seen as wasteful and difficult to maintain (DRY). Processes on the back-end are also constantly running thanks to worker processes, something that can't easily be replicated on all front-ends.

TL;DR This largely depends on your actual platform and use-case but I think I can say with confidence that the majority are fine with backend-managed badge numbers.

Jai Govindani
  • 3,181
  • 21
  • 26
  • Is not it possible to use silent push and this method, - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler? will it work? [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1; ? – karim Feb 02 '18 at 11:15
  • Not guaranteed to work unless your application is in the background. If the user has force-killed your application then you will not receive this notification. So this will not work in 100% of cases. – Jai Govindani Feb 06 '18 at 09:28