2011-08-01 5 views
6

그래서 기본적으로 로컬 알림을 지속적으로 제공하는 앱을 설정하려고합니다.2 분마다 알려주는 UILocalNotification을 만드는 방법

지금까지 내가 가지고 :

- (void)scheduleNotification { 

    [reminderText resignFirstResponder]; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) { 

     UILocalNotification *notif = [[cls alloc] init]; 
     notif.fireDate = [datePicker date]; 
     notif.timeZone = [NSTimeZone defaultTimeZone]; 

     notif.alertBody = @"Your building is ready!"; 
     notif.alertAction = @"View"; 
     notif.soundName = UILocalNotificationDefaultSoundName; 
     notif.applicationIconBadgeNumber = 1; 

     NSInteger index = [scheduleControl selectedSegmentIndex]; 
     switch (index) { 
      case 1: 
       notif.repeatInterval = NSMinuteCalendarUnit; 
       break; 
      case 2: 
       notif.repeatInterval = NSMinuteCalendarUnit*2; 
       break; 
      default: 
       notif.repeatInterval = 0; 
       break; 
     } 

     NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text 
               forKey:kRemindMeNotificationDataKey]; 
     notif.userInfo = userDict; 

     [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
     [notif release]; 
    } 
} 

내가하고 1 분마다 (나는 경우 2를 설정할 때) 내가 알림을 2 분마다 얻을 수있는 그것을 만들려고 해요 (나는 경우 1을 설정 한 경우) 통보 받는다. 유일한 문제는 ... * 2는 2 분마다 알림을 받도록 작동하지 않습니다. 2 분마다 알려주기 위해 어떻게해야합니까?

답변

2

UILocalNotification의 repeatInterval 속성을 설정할 때 정의 된 일정 단위는 NSCalendarUnit에만 사용할 수 있습니다. 사용자 지정 단위를 사용하거나 단위를 조작 할 수 없으므로 알림의 반복 간격 속성을 사용하여 원하는 작업을 수행 할 수 없습니다.

알림을 2 분마다 예약하려면 대부분 다른 시간 (2 분 간격)으로 여러 알림을 예약해야합니다. 당신은 UILocalNotification을 만든 다음에 그것을 예약 할 수 있습니다 : 다음 (당신의 반복 간격을 추가하여)을 fireDate 속성을 수정

[[UIApplication sharedApplication] scheduleLocalNotification: localNotification]; 

, 다음 같은 코드로 다시 예약합니다. 루프 내에서이 작업을 반복 할 수 있지만 여러 번 알림을 반복해야합니다.

관련 문제