如何在ios中选定的工作日(周一,周日)设置闹钟。 (Localnotification)

时间:2014-06-27 08:44:08

标签: ios objective-c localnotification

嗨朋友我正在做一个警报应用,因为我需要重复警报选定日期(星期一,星期二, - )。一旦选择星期一,警报将在每个星期一开火。怎么做这个伙伴建议我。

提前谢谢。

The Repeat had selected three days(monday,Thursday,Saturday)

1 个答案:

答案 0 :(得分:0)

当运行此通知时,另外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
    }