0

它在线崩溃:

eventStoreQueue = dispatch_queue_create("com.example.nativecalexample", NULL);

// 代码

- (id)init
{
    if ((self = [super init])) {
        eventStore = [[EKEventStore alloc] init];
        if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
        {
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
             {
                 events = [[NSMutableArray alloc] init];
                 items = [[NSMutableArray alloc] init];
                 eventStoreQueue = dispatch_queue_create("com.example.nativecalexample", NULL);
                 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventStoreChanged:) name:EKEventStoreChangedNotification object:nil];
             }];
        }
    }

    return self;
}

- (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate
{
  // asynchronous callback on the main thread
  [events removeAllObjects];
  //NSLog(@"Fetching events from EventKit between %@ and %@ on a GCD-managed background thread...", fromDate, toDate);
  dispatch_async(eventStoreQueue, ^{
    NSDate *fetchProfilerStart = [NSDate date];
    NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:fromDate endDate:toDate calendars:nil];
    NSArray *matchedEvents = [eventStore eventsMatchingPredicate:predicate];
    dispatch_async(dispatch_get_main_queue(), ^{
      //NSLog(@"Fetched %d events in %f seconds", [matchedEvents count], -1.f * [fetchProfilerStart timeIntervalSinceNow]);
      [events addObjectsFromArray:matchedEvents];
      [delegate loadedDataSource:self];
    });
  });
}

编辑:当应用程序崩溃时,我在该行得到 EXC_BAD_ACCESS,截图:http: //i45.tinypic.com/2kzeu.png

4

1 回答 1

0

检查eventStoreQueue是否有效创建:

eventStoreQueue = dispatch_queue_create("com.example.nativecalexample", NULL);
NSLog(@"Created eventStoreQueue: %x", eventStoreQueue);

如果是,还要确保在进入之前任何时候都没有释放它presentingDatesFrom

于 2012-11-16T10:06:58.763 回答