Я пытаюсь сохранить мои уведомления в базе данных после их планирования. Для моей жизни я не могу получить уведомление, отображаемое в симуляторе iOS. Любая идея, что не так? Вот код делегата приложения для настройки уведомлений. В принципе, события устанавливаются как еженедельные, а строка дескриптора имеет форму «Лекция в понедельник с 5:04 до 6:09 утра». Затем я добавляю текущую дату (без времени) к времени, чтобы установить уведомление перед сохранением в базе данных. Уведомление не срабатывает, но если я показываю материал в базе данных уведомлений в виде таблицы выглядит как (нуль) (нуль)местные уведомления, не работающие в iOS
-(void)applicationDidBecomeActive:(UIApplication *)application
{
NSArray *arrrayToSetNotifications= nil;
arrrayToSetNotifications= self.getAlleventsToday;
if (arrrayToSetNotifications!=nil)
{
for (Events *event in arrrayToSetNotifications)
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy HH:mm a"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+5:30"]];
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"dd.MM.yyyy"];
[dateFormatter2 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+5:30"]];
NSDate *now=[NSDate date];
NSString *todaysdate=[dateFormatter2 stringFromDate:now];
NSDate *datefromstring = [[NSDate alloc] init];
// voila!
NSArray *words=[event.descriptorString componentsSeparatedByString:@" "];
NSString *dateString=[NSString stringWithFormat:@"%@ %@ %@",todaysdate,[words objectAtIndex:4],[words objectAtIndex:5]];
datefromstring=[dateFormatter dateFromString:dateString];
UILocalNotification *notification=[[UILocalNotification alloc]init];
notification.fireDate=datefromstring;
notification.repeatInterval=NSWeekCalendarUnit;
[application scheduleLocalNotification:notification];
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =
[appDelegate managedObjectContext];
NSManagedObject *notification2;
[notification2 setValue:datefromstring forKey:@"date"];
[notification2 setValue:0 forKey:@"attendedValue"];
[notification2 setValue:event forKey:@"event"];
notification2 = [NSEntityDescription
insertNewObjectForEntityForName:@"Notifications"
inManagedObjectContext:context];
NSError *error;
[context save:&error];
}
}
}
Хорошо, исправлено. Нет кубиков. Что мне делать? – Robin
Я обновил ответ. Вы храните данные в нераспределенном объекте ('уведомление2'), вам нужно переместить' insertNewObjectForEntityForName' до вызовов 'setValue', иначе они просто теряются в æther. – Petesh