iphone – xcode – 按时间安排本地通知(每天早上6点)

iphone – xcode – 按时间安排本地通知(每天早上6点),第1张

概述我正在使用 Xcode 4.3.2,如何在每天早上6点设置本地通知“dateToFire”? -(void)notification{ UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease]; if (!localNotification) 我正在使用 Xcode 4.3.2,如何在每天早上6点设置本地通知“datetoFire”?

-(voID)notification{    UIlocalnotification *localnotification = [[[UIlocalnotification alloc] init] autorelease];    if (!localnotification)         return;    // Current date    NSDate *date = [NSDate date];     NSDate *datetoFire = //Everyday: 6AM;    // Set the fire date/time    [localnotification setFireDate:datetoFire];    [localnotification setTimeZone:[NSTimeZone defaultTimeZone]];    [localnotification setAlertbody:@"Notification" ];          [[UIApplication sharedApplication] schedulelocalnotification:localnotification];}- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    [self notification];}
解决方法 使用CalendarComponents将小时设置为6,并将localnotification.repeatInterval设置为NSDayCalendarUnit

NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendarNSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year,month,day,hour and minutesfor today's date[components setHour:18];[components setMinute:0];localnotification.fireDate = [calendar dateFromComponents:components];
总结

以上是内存溢出为你收集整理的iphone – xcode – 按时间安排本地通知(每天早上6点)全部内容,希望文章能够帮你解决iphone – xcode – 按时间安排本地通知(每天早上6点)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1019062.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存