0

I wanna repeat a local notification message every Wednesday 6.00 pm.

How would I do that?

For the moment I use following code. But even I try, nothing happens at this time. I logged the UIDate, it shows me 0001-01-01 17:25:52. I figured out, it is the wrong time zone. I am in the CEST time zone. How would I change that?

- (void)applicationDidEnterBackground:(UIApplication *)application {

//Calendar
NSCalendar *gregCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *dateCompnent = [gregCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday fromDate:[NSDate date]];

[dateCompnent setWeekday:4];
[dateCompnent setHour:18];
[dateCompnent setMinute:00];

UIDatePicker *dd = [[UIDatePicker alloc] init];
[dd setDate:[gregCalendar dateFromComponents:dateCompnent]];

//Notification
UILocalNotification *notification = [[UILocalNotification alloc] init];
[notification setAlertBody:@"Test Notification"];
[notification setFireDate:dd.date];
[notification setSoundName:@"sound.mp3"];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];
}
hantoren
  • 357
  • 2
  • 17
  • Probably the `[NSTimeZone defaultTimeZone]` is not the correct timezone for you. Also look at [this](http://stackoverflow.com/questions/18424569/understanding-uilocalnotification-timezone) – Antonis Jul 28 '15 at 17:58
  • What is with the localTimeZone? – hantoren Jul 28 '15 at 18:05

1 Answers1

0

You've to add year, month and day to your date component.

See also this blog post for scheduling repeating local notifications.

http://useyourloaf.com/blog/2010/09/13/repeating-an-ios-local-notification.html

muenzpraeger
  • 373
  • 1
  • 5