Stefan Deutschmann
Stefan Deutschmann

Reputation: 238

scheduleLocalNotification doesn´t work

when I get the time/date from dateTimePicker.date, the Notification work, but when I fire the date with dateFromString, the notification doesn´t work.

The Code:

-(IBAction)alarmSetButtonTapped:(id)sender {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale systemLocale];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;

NSString *tmp = @"2012-09-05 10:19";
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSDate *dateFromString = [dateFormatter dateFromString: tmp];
NSLog(@"Alarm TMP %@", dateFromString);
[dateFormatter release];


[self scheduleLocalNotificationWithDate:dateFromString];
[self presentMessage:@"Alarm set"];

};

Please can you help me??

EDIT:

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = fireDate;
notification.alertBody = @"Time to wake up";
notification.soundName = @"clock.mp3";

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

[notification release];
}

Upvotes: 2

Views: 8347

Answers (1)

Rajneesh071
Rajneesh071

Reputation: 31081

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    // Set the fire date/time
    [localNotification setFireDate:yourDate];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];

    localNotification.applicationIconBadgeNumber=1;

    // Setup alert notification
    [localNotification setAlertAction:@"Open App"];
    [localNotification setAlertBody:[randonQuotesDic objectForKey:@"Rajneesh"]];
    [localNotification setAlertBody:@"You had set a Local Notification on this time"];

    localNotification.soundName=UILocalNotificationDefaultSoundName;
    [localNotification setHasAction:YES];      
    UIApplication *app=[UIApplication sharedApplication];
    [app scheduleLocalNotification:localNotification];

Upvotes: 7

Related Questions