2016-02-16 103 views
0

我是iOS新手。我正在做一個鬧鐘應用程序,我想實現重複功能。我搜索了很多,並且不知道如何做到這一點。我知道這是通過通知方式完成的。我被困住了。請任何人告訴我解決方案。這是我的代碼,當用戶保存報警。報警中重複功能

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
dateFormatter.timeZone = [NSTimeZone defaultTimeZone]; 
NSLog(@"dateformater %@",dateFormatter); 
dateFormatter.timeStyle = NSDateFormatterShortStyle; 
NSString * dateTimeString = [dateFormatter stringFromDate:timePicker.date]; 
NSLog(@"date time string %@",dateTimeString); 

[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:NSLocaleIdentifier]]; 
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 
datesArray = @[[dateFormatter stringFromDate:self.timePicker.date]]; 
NSLog(@"dates array is %@",datesArray); 

[datesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) 
{ 
    NSArray * repeatDays = [repeatResult componentsSeparatedByString:@","]; 
    for (NSString * days in repeatDays) 
    { 
     if ([days isEqualToString:@"Sun"]) 
     { 
      [self getDateOfSpecificDay:1]; 

     } 
     if ([days isEqualToString:@"Mon"]) 
     { 
      [self getDateOfSpecificDay:2]; 

     } 
     if ([days isEqualToString:@"Tue"]) 
     { 
      [self getDateOfSpecificDay:3]; 

     } 
     if ([days isEqualToString:@"Wed"]) 
     { 
      [self getDateOfSpecificDay:4]; 

     } 
     if ([days isEqualToString:@"Thu"]) 
     { 
      [self getDateOfSpecificDay:5]; 

     } 
     if ([days isEqualToString:@"Fri"]) 
     { 
      [self getDateOfSpecificDay:6]; 

     } 
     if ([days isEqualToString:@"Sat"]) 
     { 
      [self getDateOfSpecificDay:7]; 

     } 



    } 





}]; 

AlarmObject * alarm = [[AlarmObject alloc] init]; 
alarm.repeatData = repeatResult; 
alarm.clockDate = dateTimeString; 

[self.delegate alarmSetting:alarm]; 
[self scheduleLocalNotificationWithDate:timePicker.date]; 
[self.navigationController popViewControllerAnimated:YES]; 

,這裏是我的scheduledLocalNotification mehtod

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate 
{ 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
localNotif.alertBody = @"Time to wake Up"; 
localNotif.alertAction = @"Show me"; 
localNotif.soundName = @"Tick-tock-sound.mp3"; 
localNotif.applicationIconBadgeNumber = 1; 
localNotif.repeatInterval = NSCalendarUnitWeekOfYear; 
NSLog(@"%@",[NSDate date]); 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];` 

我堅持了下來,從過去的4天。我知道我的問題是重複的,但我不確定如何實現該邏輯。提前致謝。

回答

0

更改

dateFormatter.timeZone = [NSTimeZone defaultTimeZone]; 

dateFormatter.timeZone = [NSTimeZone localTimeZone]; 

,並檢查了this教程重複fucntionailty。