iphone – 每30分钟有一次重复间隔的问题
发布时间:2020-12-14 19:52:53 所属栏目:百科 来源:网络整理
导读:我试图每30分钟重复一次本地通知,但我的代码不能正常工作……如果你帮助我找到解决方案,我将不胜感激,这是我的代码: UILocalNotification *reminderNote = [[UILocalNotification alloc]init];reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNo
我试图每30分钟重复一次本地通知,但我的代码不能正常工作……如果你帮助我找到解决方案,我将不胜感激,这是我的代码:
UILocalNotification *reminderNote = [[UILocalNotification alloc]init]; reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 30]; reminderNote.repeatInterval = NSHourCalendarUnit; reminderNote.alertBody = @"some text"; reminderNote.alertAction = @"View"; reminderNote.soundName = @"sound.aif"; [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote]; 解决方法
firedate设置通知第一次触发的时间,repeatInterval是通知重复之间的间隔.因此,问题中的代码会安排从现在开始30分钟(60 * 30秒)的通知,然后每小时重复一次.
不幸的是,您只能安排通知以NSCalendar constants定义的确切间隔重复:例如,每分钟,每小时,每天,每月,但不是这些间隔的倍数. 幸运的是,要每30分钟收到一次通知,你可以安排两个通知:一个是现在,一个是30分钟,然后每小时重复一次.像这样: UILocalNotification *reminderNote = [[UILocalNotification alloc]init]; reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 30]; reminderNote.repeatInterval = NSHourCalendarUnit; reminderNote.alertBody = @"some text"; reminderNote.alertAction = @"View"; reminderNote.soundName = @"sound.aif"; [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote]; reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60]; [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |