I have the following code in ViewController.m:
-(void) checker {
UILocalNotification *notification = [[UILocalNotification alloc] init];
[notification setAlertBody: @"Im your local notification"];
[notification setFireDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
[notification setTimeZone: [NSTimeZone defaultTimeZone]];
[UIApplication setScheduledLocalNotifications: [NSArray arrayWithObject: notification]];
}
The last line produces a warning:
Class method ‘+setScheduledLocalNotifications’ not found (return type defaults to id)
and it gives error while processing. How can I instantiate the notification? As I said I am new, if you can provide a complete answer it will be greatly appreciated.
Edit: I have a timer that repeats itself every 60 seconds and calls a function that puts a notification.
timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(checker) userInfo:nil repeats:YES];
/* ... */
-(void)checker {
NSLog(@"Notification routine");
UIApplication* app = [UIApplication sharedApplication];
NSArray *oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.(if needed)
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];
// Create a new notification.
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
if (alarm) {
alarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.alertBody = @"Msg to show";
[app scheduleLocalNotification:alarm];
}
}
I can see the log only firing once a minute, but the oldNotifications count does not increase.
This is how I do it,
update:
now if I call this method twice,
the first alarm will be canceled,,