在特定日期和时间通知

时间:2014-03-05 14:54:38

标签: iphone objective-c

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

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];

1 个答案:

答案 0 :(得分: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;
相关问题