添加本地消息提醒

- (void)addLocationNotificationWithGetUpTime:(NSString *)getUpTime LunchTime:(NSString *)lunchTime SleepTime:(NSString *)sleepTime DrinkIndex:(int)drinkIndex
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];//结束计划通知
    NSArray *fireDateArray = [self getNotificationTimesFromGetUpTime:getUpTime LunchTime:lunchTime SleepTime:sleepTime];
    NSMutableArray *fireDateMutableArray = [NSMutableArray arrayWithArray:fireDateArray];
    NSArray *bodyArray = @[
                              @"亲,早起第一杯水,",
                              @"脖子扭扭 ,屁股扭扭 ,01F47B",
                              @"下午茶时间,快来杯8",
                              @"离休息还有两个小时,喝一杯1F319"];
    NSMutableArray *bodyStrArray = [NSMutableArray arrayWithArray:bodyArray];
    if (drinkIndex < bodyArray.count) { // 如果在某提醒时间之前完成,则取消该次提醒
        [bodyStrArray removeObjectAtIndex:drinkIndex];
        [fireDateMutableArray removeObjectAtIndex:drinkIndex];
    }
    NSLog(@"fireDateMutableArray = %@",fireDateMutableArray);
    //初始化本地通知
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    for (int i = 0; i < fireDateMutableArray.count; i ++) {
        //触发通知的时间
//        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:20+5*i];
        notification.fireDate = [UIUtils dateFromString:[fireDateMutableArray objectAtIndex:i] formate:@"HH:mm"];
        //通知重复提示的单位,可以是天、周、月
        notification.repeatInterval = NSDayCalendarUnit;
        //时区
        notification.timeZone = [NSTimeZone defaultTimeZone];
        // 设置应用程序右上角的提醒个数
        notification.applicationIconBadgeNumber ++;
        //通知被触发时播放的声音
        notification.soundName = UILocalNotificationDefaultSoundName;
        //通知信息
        notification.alertBody = [NSString stringWithFormat:@"%@",[bodyStrArray objectAtIndex:i]];
        //执行通知注册
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值