我尝试每天中午 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];
最佳答案
您没有设置通知的 repeatInterval
属性,并且您的日期组件缺少月、年和日。默认值为零,因此您的 fireDate
早在过去。
此外,您可能希望使用 NSGregorianCalendar
而不是 NSPersianCalendar
。
关于iphone - iOS 每天在特定时间触发本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045470/