【问题标题】:How to set alarm on selected weekdays(MonDay,Sunday) in ios. (Localnotification)如何在 ios 中的选定工作日(星期一、星期日)设置闹钟。 (本地通知)
【发布时间】:2014-06-27 08:44:08
【问题描述】:

嗨朋友们,我正在做一个闹钟应用程序,因为我有要求在选定的日子重复闹钟(星期一,星期二,--)。一旦选择星期一,警报将在每个星期一响起。如何做到这一点任何朋友建议我。

提前谢谢。

【问题讨论】:

    标签: ios objective-c localnotification


    【解决方案1】:

    当通知触发时,再运行 7 周。

       NSDate *localDate = [NSDate date];
    NSDateFormatter *dateFormatter1 = [[[NSDateFormatter alloc]init]autorelease];
    dateFormatter1.dateFormat = @"EEEE MMMM d, yyyy";
    
    NSString *dateString = [dateFormatter1 stringFromDate: localDate];
    
    NSLog(@"date:%@",dateString);
    for (int i=0; i<8; i++) {
    
    
        // How much day to add
        int addDaysCount = i;
    
        // Creating and configuring date formatter instance
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"];
    
        // Retrieve NSDate instance from stringified date presentation
        NSDate *dateFromString = [dateFormatter dateFromString:dateString];
        //        NSLog(@"dateFormmater:%@",dateFromString);
        // Create and initialize date component instance
        NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
        [dateComponents setDay:addDaysCount];
    
        // Retrieve date with increased days count
        NSDate *newDate = [[NSCalendar currentCalendar]
                           dateByAddingComponents:dateComponents
                           toDate:dateFromString options:0];
    
        NSString* weekDayString=[dateFormatter stringFromDate:newDate];
        NSLog(@"New date: %@", [dateFormatter stringFromDate:newDate]);
       //here check the selected week is in your Selectedweeks array then add notification
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2021-03-04
      • 2011-10-12
      相关资源
      最近更新 更多