2017-02-23 9 views
0

EKEventが追加されたか削除されたかを知る方法は?私はイベントの通知をスケジュールすることができます。それ以外の場合は、削除されたイベントの通知もスケジュールされます。どんな助け?イベントストアの変更を検出する方法と変更点は何ですか? EKEventStoreChangedNotificationより

-(void)storeChanged:(NSNotification*)notification{ 

    EKEventStore *ekEventStore = notification.object; 

    NSDate *now = [NSDate date]; 
    NSDateComponents *offsetComponents = [NSDateComponents new]; 
    [offsetComponents setDay:0]; 
    [offsetComponents setMonth:4]; 
    [offsetComponents setYear:0]; 
    NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:offsetComponents toDate:now options:0]; 

    NSArray *ekEventStoreChangedObjectIDArray = [notification.userInfo objectForKey:@"EKEventStoreChangedObjectIDsUserInfoKey"]; 
    NSPredicate *predicate = [ekEventStore predicateForEventsWithStartDate:now 
                     endDate:endDate 
                    calendars:nil]; 
    // Loop through all events in range 
    [ekEventStore enumerateEventsMatchingPredicate:predicate usingBlock:^(EKEvent *ekEvent, BOOL *stop) { 
     // Check this event against each ekObjectID in notification 
     [ekEventStoreChangedObjectIDArray enumerateObjectsUsingBlock:^(NSString *ekEventStoreChangedObjectID, NSUInteger idx, BOOL *stop) { 
      NSObject *ekObjectID = [(NSManagedObject *)ekEvent objectID]; 
      if ([ekEventStoreChangedObjectID isEqual:ekObjectID]) { 
       // Log the event we found and stop (each event should only exist once in store) 
       NSLog(@"calendarChanged(): Event Changed: title:%@", ekEvent.title); 

       NSLog(@"%@",ekEvent); 

       NSInteger total = [[[UIApplication sharedApplication] scheduledLocalNotifications]count]; 
       if (total == 64) { 
        [self cancelLastNotification]; 
       } 

       NSArray *newArray = [[NSArray alloc]initWithObjects:ekEvent, nil]; 
       [self scheduleNotificationForCalendarEvents:NO andEvents:newArray]; 

       *stop = YES; 
      } 
     }]; 
    }]; 

} 

答えて

0

あなたがrefreshプロパティを使用している場合、それが削除されているとき、それはfalseを返します、そしてあなたはまだそれを使用することができている場合はtrue。

関連する問題