iOS每天在特定时间点火本地通知

时间:2012-01-28 13:09:39

标签: iphone ios xcode ipad

我正在尝试每天凌晨12:01发出本地通知,但我不知道为什么我的代码不起作用。你能帮我找到问题吗?

local = [[UILocalNotification alloc]init];

NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSPersianCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];

//edited:
[dateComps setYear:1390]; //2012
[dateComps setMonth:10]; //1
[dateComps setDay:9];    //29

 local.repeatInterval = 5;

[dateComps setHour:00];
[dateComps setMinute:1];
[dateComps setSecond:00];


local.fireDate = [calendar dateFromComponents:dateComps];
local.alertBody = @"HELLO";
local.alertAction = @"View";
local.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication]scheduleLocalNotification:local];

1 个答案:

答案 0 :(得分:3)

您没有设置通知的repeatInterval属性,并且您的日期组件缺少一个月,一年和一天。默认值为零,因此您的fireDate已回过头。

此外,您可能希望使用NSGregorianCalendar代替NSPersianCalendar

相关问题