2011-03-03 2 views
4

좋아요, 그래서 몇 가지 주어진 옵션 (매분/시간/일/주/월 등)을 반복하기 위해 UILocalNotification을 설정할 수 없다고 말하는 몇 가지 게시물을 보았습니다.NSWeekdayCalendarUnit을 사용하여 UILocalNotifications repeatInterval

그러나 repeatInterval 속성을 UILocalNotification에서 NSWeekdayCalendarUnit으로 설정하는 내용에 대해서는 다루지 않았습니다.

나는이 NSDate와 NSCalendar에 매우 익숙하다. 그래서 나는 무엇인가 놓치고 있다고 확신한다. 그러나 나는 문서를 읽었고, 너는 NSWeekdayCalendarUnit을 사용할 수있는 것처럼 들린다. NSLocalNotification 반복을 말한다. 월요일, 화요일, 목요일은 NSWeekdayCalendarUnit이 2,3,5로 설정된 경우입니다.

NSWeekdayCalendarUnit 요일 단위를 지정합니다. 해당 값은 int입니다. kCFCalendarUnitWeekday와 같습니다. 평일 단위는 1에서 N까지의 숫자입니다 (그레고리력 N = 7 및 1은 일요일 임).

맞지 않습니까?

미리 감사드립니다.

답변

1

예. 가능합니다. 나는 이것을 좋아한다. 사용자는 선택 도구로 체계를 선택할 수 있습니다. 그리고 다음 선택 방법으로갑니다 :

- (void)setOneLocalAlarmNotification: (NSDate *)firstFireDate withRepeat: (NSInteger)repeat { 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
    return; 
localNotif.fireDate = firstFireDate; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 
localNotif.repeatCalendar = [NSCalendar currentCalendar]; 

switch(repeat) { 
    case 0: 
     break ; 
    case 1: 
     localNotif.repeatInterval = kCFCalendarUnitDay; 
     break; 
    case 2: 
     localNotif.repeatInterval = kCFCalendarUnitWeekday; 
     break; 
    default: 
     break; 
} 

// Notification details 
localNotif.alertBody = @"Message?"; 
// Set the action button 
localNotif.alertAction = @"Yes"; 

localNotif.soundName = @"glas.caf"; //UILocalNotificationDefaultSoundName; 
localNotif.applicationIconBadgeNumber = 1; 

// Specify custom data for the notification 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:@"type"]; 
    localNotif.userInfo = infoDict; 

// Schedule the notification 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
[localNotif release] 
} 
+1

만약 내가 이것을 이해한다면, '반복'을 위해 1을 건네면 로컬 통보가 매일 반복되도록 설정합니다. '반복'을 위해 2를 전달하면 평일에만 반복됩니다 (따라서 월 - 금, 토 ​​및 일 제외). 또는 'kCFCalendarUnitWeekeday'의 값을 임의로 3로 설정하여 매주 화요일에 지역 알림을 반복하도록 설정할 수 있습니다. – Justin

관련 문제