添加本地消息提醒

- (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];
    }
}


你可能感兴趣的:(添加本地消息提醒)