Это странно . Мое приложение планирует локальные уведомления всякий раз, когда оно отправляется в фоновом режиме, и, хотя первое уведомление отображается правильно, как только после этого должно быть запущено, все приложение падает. Да, на заднем плане. Пока код не выполняется.
Не выводится консоль, я просто получаю диалоговое окно с надписью «Симуляция приложения завершена» в симуляторе iPhone. На реальном iPhone меня выкидывают обратно на трамплин.
Вот соответствующий код для уведомлений. Спасибо за вашу помощь.
- (void)scheduleLocalNotificationsForAlarmsWithNextAlarmAt:(NSDate *)theFireDate ofType:(int)workPlayType {
BOOL backgroundSupported = NO;
UIDevice* device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
backgroundSupported = device.multitaskingSupported;
if(!backgroundSupported) return;
int work_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"work_minutes_preference"];
int play_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"play_minutes_preference"];
int workPlayStatusForNotif = workPlayType;
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
if (workPlayStatusForNotif == 1) {
localNotif.alertBody = @"Work";
localNotif.repeatInterval = work_minutes;
} else {
localNotif.alertBody = @"Play";
localNotif.repeatInterval = play_minutes;
}
localNotif.fireDate = theFireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.soundName = @"ding.caf";
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
// now the other one
localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
if (workPlayStatusForNotif == 0) {
localNotif.alertBody = @"Work";
localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)work_minutes*60];
localNotif.repeatInterval = work_minutes;
} else {
localNotif.alertBody = @"Play";
localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)play_minutes*60];
localNotif.repeatInterval = play_minutes;
}
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.soundName = @"ding.caf";
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}