- Registriert
- 19.10.14
- Beiträge
- 48
Hallo
Ich möchte gerne eine Local-Notification so einrichten, dass jeden Montag bzw. Mittwoch um 19:00 Uhr eine Nachricht rausgeht, welche den Nutzer informiert. Mein momentaner Code:
1. Frage: Irgendetwas muss mit dem Datum falsch sein. Wenn ich nämlich mal meine "notification" logge bekomme ich folgende Nachricht. Irgend etwas muss mit dem Datum falsch sein, oder sehe ich das falsch?:
<UIConcreteLocalNotification: 0x7fbb21436d60>{fire date = Thursday, January 1, 2015 at 7:00:00 PM Central European Standard Time, time zone = Europe/Zurich (GMT+2) offset 7200 (Daylight), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = (null), user info = (null)}
2. Frage: Ich möchte gern jeden Montag & Mittwoch eine Nachricht senden. Wie bekomme ich es hin, in der "setWeekday" mehrere Tage zu setzen?
Gruss
Ich möchte gerne eine Local-Notification so einrichten, dass jeden Montag bzw. Mittwoch um 19:00 Uhr eine Nachricht rausgeht, welche den Nutzer informiert. Mein momentaner Code:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
return YES;
}
Code:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *now = [NSDate date];
NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond | NSCalendarUnitWeekday) fromDate: now];
[componentsForFireDate setWeekday:2];
[componentsForFireDate setHour: 19] ;
[componentsForFireDate setMinute:00] ;
[componentsForFireDate setSecond:00] ;
NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
// Create the notification
UILocalNotification *notification = [[UILocalNotification alloc] init] ;
notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone];
notification.alertTitle = [NSString stringWithFormat:@"Titel"];
notification.alertBody = [NSString stringWithFormat: @"Nachricht"] ;
notification.soundName = @"sound.mp3";
NSLog(@"%@", notification);
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
1. Frage: Irgendetwas muss mit dem Datum falsch sein. Wenn ich nämlich mal meine "notification" logge bekomme ich folgende Nachricht. Irgend etwas muss mit dem Datum falsch sein, oder sehe ich das falsch?:
<UIConcreteLocalNotification: 0x7fbb21436d60>{fire date = Thursday, January 1, 2015 at 7:00:00 PM Central European Standard Time, time zone = Europe/Zurich (GMT+2) offset 7200 (Daylight), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = (null), user info = (null)}
2. Frage: Ich möchte gern jeden Montag & Mittwoch eine Nachricht senden. Wie bekomme ich es hin, in der "setWeekday" mehrere Tage zu setzen?
Gruss