2014-03-05 36 views
0

所以我需要你的帮助:我必须在特定的日期和时间设置代码通知。请帮我解决我的代码。在特定的日期和时间通知

UILocalNotification* n1 = [[UILocalNotification alloc] init]; 
n1.fireDate = [NSDate dateWithTimeIntervalSinceNow: 6]; 
n1.alertBody = @"one"; 
UILocalNotification* n2 = [[UILocalNotification alloc] init]; 
n2.fireDate = [NSDate dateWithTimeIntervalSinceNow: 15]; 
n2.alertBody = @"two"; 
[[UIApplication sharedApplication] scheduleLocalNotification: n1]; 
[[UIApplication sharedApplication] scheduleLocalNotification: n2]; 
+2

什么问题?什么不行?两个代码? – Larme

+1

什么不起作用(即你的具体问题是什么)? – tilo

+0

通知应该在特定日期工作 – mazeen

回答

1

看来你只是不知道如何创建一个NSDate到一个特定的时间。使用NSDateFormatter将字符串转换为日期。

NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
[df setDateFormat:@"yyyy-MM-dd HH:mm"]; 
NSDate *myDate = [df dateFromString:@"2014-04-05 23:30"]; 

UILocalNotification* n1 = [[UILocalNotification alloc] init]; 
n1.fireDate = myDate; 
+0

请有人帮我解决当我运行我的第一(@“ONE”)通知必须在特定时间运行 – mazeen