【发布时间】:2014-01-20 19:25:05
【问题描述】:
我正在尝试在安排通知后将通知存储在数据库中。对于我的生活,我无法让通知显示在 iOS 模拟器中。知道出了什么问题吗?这是用于设置通知的应用程序委托代码。基本上,事件设置为每周一次,描述符字符串的格式为“Lecture on Monday from 5:04 AM to 6:09 AM”。然后我将当前日期(没有时间)添加到时间以在存储到数据库之前设置通知。通知没有启动,但如果我在表格视图中显示通知数据库中的内容,它看起来像 (null)(null)
-(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];
}
}
}
【问题讨论】:
标签: ios objective-c uilocalnotification