4

My app I'm developing is a alarm type app. When the user presses the home button, I schedule a few UILocalNotifications to fire at certain intervals. The notifications fire at the right time when I press the home button and exit the app, but they don't fire at all if I press the Lock button. I've searched around but haven't found out why this is yet.

As I said, it works fine when I press the home button first. They fire at the right times, but if I press the "Lock" button at the top of the phone they don't fire after that. Anybody have any ideas as to why this is?

Thanks

Dk Kumar
  • 103
  • 1
  • 11
ColaCube
  • 71
  • 3

2 Answers2

0

This is because the lock button does not exit your application.

I assume you are setting up the UILocalNotifications in applicationWillTerminate: in your application delegate. If you add some logging in this method, you will see that it isn't called when using the lock button.

Setting up your notifications in applicationWillResignActive: might solve your problem.

Rein Spijkerman
  • 604
  • 5
  • 15
0

I know this is super late, but might help someone. This issue has been so overlooked on SO and no tutorial over the internet. Anyway, what you need to do is set UIUserNotificationActivationModeBackground when setting UIUserNotificationSettings, and you should be good to go.

Code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationActivationModeBackground categories:nil];
    [application registerUserNotificationSettings:settings];
   }
   return YES;
}

Hope this helps.

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
Tejas K
  • 682
  • 11
  • 28