请求访问日历时,iOS 6应用程序崩溃

时间:2012-11-16 09:15:04

标签: iphone crash calendar ios6

它在行崩溃:

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

1 个答案:

答案 0 :(得分:0)

检查eventStoreQueue是否有效创建:

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

如果是,请确保在进入presentingDatesFrom之前不会释放它。