iphone - iOS 每天在特定时间触发本地通知

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

最佳答案

您没有设置通知的 repeatInterval 属性,并且您的日期组件缺少月、年和日。默认值为零,因此您的 fireDate 早在过去。

此外,您可能希望使用 NSGregorianCalendar 而不是 NSPersianCalendar

关于iphone - iOS 每天在特定时间触发本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9045470/

相关文章:

iphone - 如何在 Objective-C 中的另一个方法中调用一个方法

iphone - 在Friend Wall发表期间Facebook返回com.facebook.sdk错误5

c# - iOS 5 中的 NSJSONSerialization 就像 c# 序列化到类

ios - Interface Builder 中的 Dead Outlets/Actions 错误

ios - 如何解决 "code couldn' t 找到匹配 'com.example.hello' 的配置文件。”?

iphone - iOS 4.3 中 UITextView beginningOfDocument 中的问题

iphone - 应用程序仅在设备上运行时崩溃,警告 "Application ' xxxxxxx' 异常退出,信号 11 : Segmentation fault: 11.“

ios - 在 dispatch_once(&onceToken, ^{

ios - 更改 UISplitViewController iOS 8 中的详细导航项

iOS - .ipa 文件上的应用程序调试