首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILocalNotification发行

UILocalNotification发行
EN

Stack Overflow用户
提问于 2014-12-12 10:38:18
回答 1查看 43关注 0票数 0

我已安排我的本地通知在下午4时,并希望该通知每天下午4时,但通知之前的时间在下午3时44分,下午3时47分等。

这是密码-

代码语言:javascript
复制
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) fromDate:self.datePicker.date];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:self.datePicker.date];
[dateComponents setHour:[timeComponents hour]];
[dateComponents setMinute:[timeComponents minute]];
[dateComponents setSecond:0.0];

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = [NSString stringWithFormat:@"How are you feeling?"];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.fireDate = [calendar dateFromComponents:dateComponents];
localNotification.repeatInterval = kCFCalendarUnitDay;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
EN

回答 1

Stack Overflow用户

发布于 2014-12-12 11:25:38

试试这个:

代码语言:javascript
复制
NSDate *myDate = [NSDate date]; // Set your time here
myDate = [myDate dateByAddingTimeInterval:1*24*60*60];
UILocalNotification  *notif = [[UILocalNotification alloc] init];
notif.fireDate = myDate;
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = [NSString stringWithFormat:@"How are you feeling?"];
notif.alertBody = @"Reminder is set";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];

希望它能帮到你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27441794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档