0

I am using badge notifications in my app and it works fine but I get the badge number by calling a method. So if method is called then the badge number gets increased but how to call that method while app is closed.

  - (void)repeatedMethod {

    SOWObject *object =[[SOWObject alloc]init];
    [object getBadgeNumber:[self getDBPath]];

    // I get badgeArray from above method

     [UIApplication sharedApplication].applicationIconBadgeNumber=badgeArray.count;

    }

is there any way we can call this method each day when date is changed and update badge number.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

2

So far as I know, you can do this with 3 options:

  1. Use Silent notification - for iOS7 and above only. a bit complicated since you need to enable Push and do back-end intergration
  2. Use Background refresh - Create a timer + UIBackgroundTaskIdentifier. (not 100% sure)
  3. Use Local/Push Notification - disadvantage using this, user knows of such notification is triggered.
HelmiB
  • 12,303
  • 5
  • 41
  • 68
0

implement this delegate method in your appdelegate:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif

This method is fired whenever the OS finds any local notifications.(it doesn't matter whether your app is in the background or in the foreground).

For more information & code look here

Look at the accepted answer.

Edited: Answer for you to call a method while app is in background is here

So, it basically says not all the apps have access to background execution. Officially it's mentioned in the apple's developer site also: HERE

Community
  • 1
  • 1
Bikram Thapa
  • 1,329
  • 1
  • 16
  • 29