Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何记录用于本地通知的日期?_Ios_Objective C_Cocoa Touch_Notifications - Fatal编程技术网

Ios 如何记录用于本地通知的日期?

Ios 如何记录用于本地通知的日期?,ios,objective-c,cocoa-touch,notifications,Ios,Objective C,Cocoa Touch,Notifications,我正在尝试记录我的通知发出的日期,但没有记录日期 假设我有这个代码,我需要它在周日启动,以下是我尝试过的,以及之后的结果: -(void) Sunday { // 9th Notification Every 1:35 NSCalendar *calendar = [NSCalendar currentCalendar]; calendar.timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; NSDateComponents *compone

我正在尝试记录我的通知发出的日期,但没有记录日期

假设我有这个代码,我需要它在周日启动,以下是我尝试过的,以及之后的结果:

-(void) Sunday {   // 9th Notification Every 1:35

NSCalendar *calendar = [NSCalendar currentCalendar];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];

NSDateComponents *components = [calendar components:NSWeekCalendarUnit fromDate:[NSDate date]];

components.weekday = 1;
components.hour   = 22;
components.minute = 38;
components.second = 25;

NSDate *fire = [calendar dateFromComponents:components];
NSLog(@"The Fire day is:: %@", fire);

UILocalNotification *notif = [[UILocalNotification alloc]  init] ;
if (notif == nil)
    return;

notif.fireDate = fire;
notif.repeatInterval= NSWeekCalendarUnit ;
notif.soundName = @"ring.wav";
notif.alertBody = [NSString stringWithFormat: @"THANKS for Your HELP :)"] ;
[[UIApplication sharedApplication] scheduleLocalNotification:notif] ;
}
日志显示:

2014-01-19 22:37:45.470 daily notification test[15595:c07] The Fire day is:: 0001-01-21 22:38:25 +0000
我只是想在一周中的每一天发送一个通知,不管是哪一个月,哪一年。。但它仅在定义小时和使用
NSHourCalendarUnit
时适用


非常感谢您的帮助。

由于您没有设置年份,因此它似乎不起作用,因此默认为0001。不要只从当前日期开始取
NSWeekCalendarUnit
,还要取年份。

虽然我需要它,但没有月份和年份,但我确实尝试过,仍然没有工作。它将显示2014年和今天的日期!我需要它在我指定的一周中的任何一天工作,无论日期如何。您需要设置正确的第一个日期。你不能从过去的日期开始。然后它会在第一次火灾后重复。这是我在尝试NSYearCalendarUnit时得到的结果,这个输出
2014-01-20 01:09:17.187每日通知测试[16302:c07]火灾日期是::2014-01-20 01:08:45+0000
,但我仍然没有看到任何通知显示在模拟器上!为什么?尝试使用
DateWithTimeIntervalencesInnow:5
创建fire日期,作为一个健全性检查(因此没有使用日期组件)。实际上,我使用
NSHourCalendarUnit
执行了不同的健全性检查,无论是哪一天,它都能在小时内正常工作!!因此,
NSWeekCalendarUnits
或day设置肯定有问题。