Segev
Segev

Reputation: 19303

UILocalNotification not showing

My goal is to send the user local notifications while the app is in the background. I've started testing out local notifications without success. I've tried adding this [self initializeNotification]; inside a UIButton action.

The debugger enters the alarm if but the notification is not showing.

-(void) initializeNotification
{
    UILocalNotification *alarm = [[UILocalNotification alloc] init];
    if (alarm)
    {
        NSLog(@"Bla");
        alarm.fireDate = nil;
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Test message...";
        [[UIApplication sharedApplication] scheduleLocalNotification:alarm];
    }

Upvotes: 1

Views: 2475

Answers (1)

Magic fish
Magic fish

Reputation: 88

The fire date is interpreted according to the value specified for timeZone. If the specified value is nil or is a date in the past, the notification is delivered immediately. And, when your app is active, the localNotification not present, it onley call the delegate

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

So, if you want see the notification in MessageCenter, you must set a fireDate

Upvotes: 2

Related Questions