UILocalNotification每天两次

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

我想每天两次点击当地通知,例如:每天早上7点,每天早上6点,所以任何人都可以帮我,我该怎么办?

I want to fire local notification twice everyday like for ex:- morning 7am and evening 6pm everyday so can anyone please help me how can i do that?

无法设置自定义时间点火本地通知已查看每个地方,但没有任何帮助,一天两次火本地通知,如果有任何帮助将很高兴地欣赏

unable to set custom time to fire the local notification have looked every where but nothing helpful for fire local notification twice in a day if any help will appreciate graetly

提前谢谢:)

这是我使用本地通知的代码的和平,但它根本没有解雇:(

this is the peace of code i am using local notification but it's not firing at all :(

- (void)scheduleNotification { [[UIApplication sharedApplication] cancelAllLocalNotifications]; Class cls = NSClassFromString(@"UILocalNotification"); if (cls != nil) { NSString *end = @"2013-09-20 11:24:00 +0000"; NSDate *endDate = [self convertStringToDate:end]; NSLog(@"end date :%@", endDate); UILocalNotification *notif = [[cls alloc] init]; notif.fireDate = endDate; notif.timeZone = [NSTimeZone defaultTimeZone]; notif.alertBody = @"Did you forget something?"; notif.alertAction = @"Show me"; notif.soundName = UILocalNotificationDefaultSoundName; notif.applicationIconBadgeNumber = 1; notif.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; [notif release]; } }

推荐答案

最后获得解决方案如何在早上7点和下午6点设置 UILocalNotification 并每天重复它希望它有助于谁在通知上寻找相同的解决方案

Finally Got the solution how to set UILocalNotification for 7am and 6pm and repeat it daily hope it help who are looking fore same solutions on notification

-(void)scheduleNotification { [[UIApplication sharedApplication] cancelAllLocalNotifications]; Class cls = NSClassFromString(@"UILocalNotification"); if (cls != nil) { NSDate *now = [NSDate date]; NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now]; [components setHour:7]; [components setMinute:0]; NSDate *today7am = [calendar dateFromComponents:components]; UILocalNotification *notif = [[cls alloc] init]; notif.fireDate = today7am; notif.timeZone = [NSTimeZone defaultTimeZone]; notif.repeatCalendar = [NSCalendar currentCalendar]; notif.alertBody = @"Did you forget something?"; notif.alertAction = @"Show me"; notif.soundName = UILocalNotificationDefaultSoundName; notif.applicationIconBadgeNumber = 1; notif.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; [notif release]; NSCalendar *calendar2 = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDateComponents *components2 = [calendar2 components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now]; [components2 setHour:18]; [components2 setMinute:0]; NSDate *today6pm = [calendar2 dateFromComponents:components2]; UILocalNotification *notif2 = [[cls alloc] init]; notif2.fireDate = today6pm; notif2.timeZone = [NSTimeZone defaultTimeZone]; notif2.repeatCalendar = [NSCalendar currentCalendar]; notif2.alertBody = @"Did you forget something2?"; notif2.alertAction = @"Show me2"; notif2.soundName = UILocalNotificationDefaultSoundName; notif2.applicationIconBadgeNumber = 1; notif2.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:notif2]; [notif2 release]; } }

更多推荐

UILocalNotification每天两次

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

发布评论

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

>www.elefans.com

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