2012-04-29 4 views
0

을 반복 13시에 이것이 어떻게 완성 되었습니까? 나는 위의 코드는이를 달성하기 위해 적용 할 수있는 방법을 이해하지 않습니다 ..UILocalNotification 화재와 내가 중간 밤에 매일 현지 통지를 발사에 사용이 코드 조각이 매일 특정 시간에

고마워,

+0

나의 대답을 보아라, namaztimes는이 코드에서 발사 시간을 가지고있는 나의 배열이다. 나는이 지역의 notoification을 하루에 5 번 (매일 같이) 해고해야한다. 그래서 이것을 사용자 정의 할 수있다. – Charan

답변

3

당신은 당신이 매일 알림을 발사 할 수있는 시간이 있다면, 당신은해야 할이

는 주요 알림 발사 방법
[self scheduleNotificationForDate:myNewDate];

에 연결 여기에서 다음
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    NSDateComponents *components = [[NSDateComponents alloc] init]; 
    for (NSMutableArray * arrDay in self.namaztimes) { 
     NSLog(@"Alarm Array: %@", arrDay); 
     int count=[arrDay count]; 
     if(!count){ 
      continue; 
     } 

     int day =0; 
     int month=0; 
     int year=0; 
     int hour =0; 
     int minutes=0; 

     // NSArray *arrDates=[[NSMutableArray alloc] initWithCapacity:1]; 
     for (int i=0;i<3;i++) { 
      NSString * dayTime=[arrDay objectAtIndex:i ]; 
      if (i==0) { 
       day = [dayTime intValue];  
      }else if(i==1){ 
       month = [dayTime intValue];      
      }else if(i==2){ 
       year = [dayTime intValue];  

      } 
     } 
     for (int i=3;i<count;i++) { 
      NSString * dayTime=[arrDay objectAtIndex:i ]; 
      hour = [[dayTime substringToIndex:2] intValue]; 
      minutes = [[dayTime substringFromIndex:3] intValue]; 

      [components setDay:day]; 
      [components setMonth:month]; 
      [components setYear:year]; 
      [components setMinute:minutes]; 
      [components setHour:hour]; 


      NSDate *myNewDate = [calendar dateFromComponents:components]; 

      [self scheduleNotificationForDate:myNewDate]; 

     } 
    } 

    [components release]; 
    [calendar release]; 

-(void) scheduleNotificationForDate: (NSDate*)date { 
    /* Here we cancel all previously scheduled notifications */ 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = date; 
    NSLog(@"Notification will be shown on: %@ ",localNotification.fireDate); 

    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
    localNotification.alertBody = @"Your Notification Text"; //[NSString stringWithFormat:@"%@",date]; 
    localNotification.alertAction = NSLocalizedString(@"View details", nil); 

    /* Here we set notification sound and badge on the app's icon "-1" 
    means that number indicator on the badge will be decreased by one 
    - so there will be no badge on the icon */ 

    localNotification.repeatInterval = NSDayCalendarUnit; 
    localNotification.soundName = UILocalNotificationDefaultSoundName; 
    localNotification.applicationIconBadgeNumber = -1; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
} 
+0

whats 자기야 .namaztimes !! –

+0

그 특정 타이밍에 지역 알림을 발생시키는 타이밍이 다른 내 어레이가 있습니다. 이미 질문에 주석을 추가하여 지정했습니다. – Charan

+0

localNotification.applicationIconBadgeNumber = -1; 왜 -1일까요? 필자의 경험에 따르면 repeatInterval을 사용하는 알림 세트는 앱 아이콘에 정확한 개수를 표시하지 않습니다. – Ahmed

관련 문제