自定义本地推送通知(UILocalNotification) 星期和时间


 

//创建本地通知

UILocalNotification *localNote = [[UILocalNotificationallocinit];

//自定义(星期和时间)

NSDate * newDate = [selfgetNextWeekDay:2hour:20minute:25];

    self.localNote.fireDate = newDate;

//设置重复周期为:(若每天重复使用属性NSCalendarUnitDayNSCalendarUnitWeekDay)

    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 = @"通知";

伦理片 http://www.dotdy.com/ 

    self.localNote.alertBody = @"新的通知~~!";

//    移除旧的通知,防止重复添加

    [[UIApplicationsharedApplicationcancelAllLocalNotifications];

 

    [[UIApplicationsharedApplicationscheduleLocalNotification: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|NSarUnitSecondfromDate:[NSDatedate]];

    

    HTLog(@"设置的weekday = %d", newWeekDay);

    

    NSDateComponents *comps = [[NSDateComponentsallocinit] ;

    

    NSInteger unitFlags = NSCalendarUnitEra |

    NSCalendarUnitYear |

    NSCalendarUnitMonth |

    NSCalendarUnitDay |

    NSCalendarUnitHour |

    NSCalendarUnitMinute |

    NSCalendarUnitSecond |

    NSWeekCalendarUnit |

    NSCalendarUnitWeekday |

    NSCalendarUnitWeekdayOrdinal |

    NSCalendarUnitQuarter;

 影音先锋电影 http://www.iskdy.com/   

    comps = [[NSCalendarcurrentCalendgs 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]ByAddingTimeInterval:3600 * 24 * days];

    return newFireDate;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值