//创建本地通知
UILocalNotification *localNote = [[UILocalNotificationalloc] init];
//自定义(星期和时间)
NSDate * newDate = [selfgetNextWeekDay:2hour:20minute:25];
self.localNote.fireDate = newDate;
//设置重复周期为:周(若每天重复使用属性NSCalendarUnitDay或NSCalendarUnitWeekDay)
self.localNote.repeatInterval = kCFCalendarUnitWeek;
self.localNote.timeZone = [NSTimeZonedefaultTimeZone];
self.localNote.alertLaunchImage = @"default-banner.png";
self.localNote.hasAction = YES;
self.localNote.soundName = UILocalNotificationDefaultSoundName;
self.localNote.alertAction = @"通知";
self.localNote.alertBody = @"新的通知~~!";
// 移除旧的通知,防止重复添加
[[UIApplicationsharedApplication] cancelAllLocalNotifications];
[[UIApplicationsharedApplication] scheduleLocalNotification:self.localNote];
/**
* 获取下一个新的星期日期
*
* @param newWeekDay 星期数值从周日算起,星期日1/星期一2/星期二3...星期六7
* @param hour 设定的小时值
* @param minute 设定的分钟值
*
* @return返回新的日期(NSDate对象)
*/
-(NSDate *)getNextWeekDay:(int)newWeekDay hour:(int)hour minute:(int)minute{
NSDateComponents * components = [[NSCalendarcurrentCalendar] components:NSCalendarUnitWeekday|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecondfromDate:[NSDatedate]];
HTLog(@"设置的weekday = %d", newWeekDay);
NSDateComponents *comps = [[NSDateComponentsalloc] init] ;
NSInteger unitFlags = NSCalendarUnitEra |
NSCalendarUnitYear |
NSCalendarUnitMonth |
NSCalendarUnitDay |
NSCalendarUnitHour |
NSCalendarUnitMinute |
NSCalendarUnitSecond |
NSWeekCalendarUnit |
NSCalendarUnitWeekday |
NSCalendarUnitWeekdayOrdinal |
NSCalendarUnitQuarter;
comps = [[NSCalendarcurrentCalendar] components:unitFlags fromDate:[NSDatedate]];
[comps setHour:hour];
[comps setMinute:minute];
[comps setSecond:0];
int temp = 0;
int days = 0;
temp = newWeekDay - components.weekday;
days = (temp >= 0 ? temp : temp + 7);
NSDate *newFireDate = [[[NSCalendarcurrentCalendar] dateFromComponents:comps] dateByAddingTimeInterval:3600 * 24 * days];
return newFireDate;
}
相关推荐
主要为大家详细介绍了iOS本地通知UILocalNotification,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
基于本地推送UILocalNotification的简单日历的实现(可以通过本地推送实现定时提醒功能)。
iOS本地通知代买实例
基于本地推送UILocalNotification的简单闹钟的实现。
在iOS8之后,以前的本地推送写法可能会出错,接收不到推送的信息
使用UILocalNotification实现本地定时推送
iOS 10 中废弃了 UILocalNotification ( UIKit Framework ) 这个类,采用了全新的 UserNotifications Framework 来推送通知,从此推送通知也有了自己的标签 UN (这待遇真是没别人了),以及对推送功能的一系列...
对闹钟完整实现, 包括程序退出后, 定时启动程序(当然也可以访问其他的东西)
本地推送通知Demo,实现小闹钟。讲解如何简单使用本地通知,并在不需要的时候,进行通知移除。对应文章链接:
本文为大家分解介绍了iOS本地推送代码的三步骤,供大家参考,具体内容如下 第一步:创建本地推送 // 创建一个本地推送 UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease]; /...
首先,我们先要明白一个概念,这里的本地通知是UILocalNotification类,和系统的NSNotificationCenter通知中心是完全不同的概念。 一、我们可以通过本地通知做什么 通知,实际上是由IOS系统管理的一个功能,比如某些...
使用NSDateComponents拼接触发通知的日期和时间点 设置UILocalNotification对象的fireDate属性,即,触发通知的具体日期时间 设置UILocalNotification对象的repeatInterval属性,即,触发通知的频率 最后使用[...
UILocalNotification的本地通知,已经实现功能,ios7.0 MRC
通过iOS的UILocalNotification Class可以实现本地app的定时推送功能,即使当前app是后台关闭状态。 可以实现诸如,设置app badgenum,弹出一个alert,播放声音等等,实现很简单 UILocalNotification *...
Iphone UILocalNotification 闹钟
本文实例为大家分享了iOS本地推送的具体代码,供大家参考,具体内容如下 首先创建全局的本地通知对象及弹出框 // 弹出本地消息 @property(nonatomic,strong)UILocalNotification *localNotification; @property...
这个助手可以让您将“远程推送通知”转换为“UILocalNotification”,并让您管理已在通知中心显示的通知。 如果要转换远程通知并将其显示为本地通知,则远程通知必须为“静默通知”(否则远程通知将显示在通知中心...
您还可以使用 UILocalNotification 类的 repeatInterval 属性来无限次显示通知,只要它不更改即可。 然而,最近,我开发了一个应用程序,它可以帮助年轻的母亲了解怀孕技巧和信息。 9 个月的每一天都必须有一个...
源码LKAlarmManager, 方便快捷的把 “您的提醒” 加入到 日历或者本地通知中,会自动处理本地通知超过64个的情况,注册下 LKAlarmManager 回调,在接收到提醒的时候,就可以做你想做的事。 使用方法: 使用例子 :...