2014-04-24 3 views
0

이것은 내 localNotification 코드입니다.NSLocalNotifications에 대한 몇 가지 질문

NSDate *currentDate = [NSDate date]; 
     NSCalendar * calendar = [NSCalendar currentCalendar]; 
     [calendar setTimeZone:[NSTimeZone systemTimeZone]]; 
     NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:currentDate]; 

     [components setTimeZone:[NSTimeZone systemTimeZone]]; 
     [components setHour:13]; 
     [components setMinute:11]; 
     [components setDay: sonOdemeGunuNumber.integerValue -3]; 

     NSDate *test = [calendar dateFromComponents:components]; 


     // Schedule the notification 
     UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
     localNotification.fireDate = test; 
     localNotification.alertBody = [NSString stringWithFormat:@"%@ 3 days left.",_txtBankaAdi.text]; 
     localNotification.alertAction = @"Show item"; 
     localNotification.timeZone = [NSTimeZone systemTimeZone]; 
     localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; 
     localNotification.repeatInterval = kCFCalendarUnitDay; 
     localNotification.repeatInterval = kCFCalendarUnitMonth; 

     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

sonOdemeGunuNumber는 ToDoItem 경고 일 (예 : 오늘 날 수 -3)입니다.

if(sonOdemeGunuNumber.integerValue == currentDay.integerValue){ 
    localNotification.repeatInterval = nil; } 

내가 3 일 이전에 사용자에게 통보하고 싶어하며 currentDay = sonOdemeGunuNumber 때까지 경고를받을 계속해야합니다.

1-이 if-else 문을 쓰면 작동할까요?

2- 사용자가 내 TableView에서 localNotification 항목을 삭제 한 경우이 경우 항목은 은행 계좌입니까? 은행 계좌 localNotification이 자동으로 삭제됩니까?

감사합니다. 이 좋은 하루 모두 ...

답변

0

나는 사용자가 내가 항목의 localNotification을 삭제 취소있는 tableview에서 항목을 삭제하는 경우에 대한 해결책 .. 모든

첫째를 발견의 LocalNotification 센터에 사용자 정보와 ID를 보냅니다.

localNotification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:_txtItemName.text,@"delThisNot", nil]; 

두 번째로 가서 tableView 메소드를 편집하십시오.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 

{ (editingStyle == UITableViewCellEditingStyleDelete) {

UIApplication *app = [UIApplication sharedApplication]; 
    NSArray *eventArray = [app scheduledLocalNotifications]; 
    for (int i=0; i<[eventArray count]; i++) 
    { 
     UILocalNotification* oneEvent = [eventArray objectAtIndex:i]; 
     NSDictionary *userInfoCurrent = oneEvent.userInfo; 
     NSString *adi = [[self.fetchedResultsController objectAtIndexPath:indexPath]valueForKey:@"odemeAdi"]; 
     NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"delThisNot"]]; 

     if ([uid isEqualToString:adi]) 
     { 
      //Cancelling local notification 
      [app cancelLocalNotification:oneEvent]; 
      break; 
     } 
    } 
} 

ADI = 삭제 항목 경우. (당신의 txtItemName.text입니다) = 귀하의 항목 ID UID

if ([uid isEqualToString:adi]) 
     { 
      //Cancelling local notification 
      [app cancelLocalNotification:oneEvent]; 
      break; 
     } 

사용자가이 통지를 취소 항목 이름 (ADI) == UID (txtItemName.Text)

을 삭제합니다. 난 그냥 다른 사람들을 돕고 싶었 내 grammers에 대한

죄송합니다 나는 너희들이 나를 이해 수 있기를 바랍니다 : D

감사합니다.