I'm writing an alarm clock iOS app. It's my first time using UILocalNotification. I'm getting the date from a date picker. I've formatted the dates to check whether my function was being passed the proper date, it was. I checked all of the needed properties for a UILocalNotification and I have them all and my notification still won't fire. Any ideas as to why? Thanks for the help.
#import "BIDAlarmViewController.h"
@interface BIDAlarmViewController ()
@end
@implementation BIDAlarmViewController
@synthesize datePicker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)setReminderUsingDateFromDatePicker: (id)sender{
[self scheduleNotificationForDate: datePicker.date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm"];
NSString *formattedDateString = [dateFormatter stringFromDate:datePicker.date];
NSLog(@"Button Pressed.. date: %@", formattedDateString);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alarm activated"
message:@"Alarm has been set"
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
-(void) scheduleNotificationForDate: (NSDate*)date {
UILocalNotification *alarm = [[UILocalNotification alloc] init];
if (alarm) {
alarm.fireDate = date;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.soundName = @"alarmsound.caf";
alarm.alertBody = @"Test message...";
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
}
}
@end