即使我的iPhone应用程序处于后台,我如何使用UILocalNotification每天晚上8点显示我的alram?
答案 0 :(得分:3)
将fireDate
设置为8.00 PM并将repeatInterval
设置为NSDayCalendarUnit
,并使用[[UIApplication sharedApplication] scheduleLocalNotification: myNotification];
答案 1 :(得分:2)
dasdom回答是正确的。只是想添加它,如果您的设备处于静音模式,闹钟将不会发出声音。这是Apple对UILocalNotification的限制。
答案 2 :(得分:0)
UILocalNotification *localNotification =[[UILocalNotification alloc]init];
NSCalendar *calendar=[NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone defaultTimeZone]];
unsigned currentFlag=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSWeekdayCalendarUnit;
NSDateComponents *comp=[calendar components:currentFlag fromDate:[NSDate date]];
comp.hour=8;
comp.minute=0;
comp.second=0;
NSDate *date=[[calendar dateFromComponents:comp]dateByAddingTimeInterval:0];
if (localNotification==nil) {
return;
}
localNotification.fireDate=date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.repeatCalendar=[NSCalendar currentCalendar];
localNotification.alertBody=@"Good Morning dude..!";
localNotification.alertAction=@"Snooze";
localNotification.repeatInterval=NSDayCalendarUnit;
localNotification.soundName=@"goodmorning.caf";
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
我希望这会对你有帮助......!