每天在特定时间安排UILocalNotification

编程入门 行业动态 更新时间:2024-10-25 06:31:58
本文介绍了每天在特定时间安排UILocalNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用下面的代码来安排特定时间的本地通知。但通知是每分钟而不是一天后重复的。我是否错过了任何通知设置。我的时区是(亚洲/加尔各答(IST)抵消19800)并使用iPhone 4s。

I am using below piece of code to schedule a localnotification at specific time. But the notification is repeating for every minute instead of after one day. Whether i have missed any notification settings. My timezone is (Asia/Calcutta (IST) offset 19800) and using iPhone 4s.

- (void)applicationDidEnterBackground:(UIApplication *)application { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ; NSDate *now = [NSDate date]; NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now]; [components setHour:12]; [components setMinute:00]; UILocalNotification *notification = [[UILocalNotification alloc]init]; notification.fireDate = [calendar dateFromComponents:components]; [notification setAlertBody:@"U got notification!!!"]; // notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }

推荐答案

你应该指定 repeatInterval 。

- (void)applicationDidEnterBackground:(UIApplication *)application { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ; NSDate *now = [NSDate date]; NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now]; [components setHour:12]; [components setMinute:00]; UILocalNotification *notification = [[UILocalNotification alloc]init]; notification.fireDate = [calendar dateFromComponents:components]; notification.repeatInterval = NSDayCalendarUnit; [notification setAlertBody:@"U got notification!!!"]; // notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; }

更多推荐

每天在特定时间安排UILocalNotification

本文发布于:2023-11-25 18:39:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   在特定   UILocalNotification

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!