它在行崩溃:
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
答案 0 :(得分:0)
检查eventStoreQueue
是否有效创建:
eventStoreQueue = dispatch_queue_create("com.example.nativecalexample", NULL);
NSLog(@"Created eventStoreQueue: %x", eventStoreQueue);
如果是,请确保在进入presentingDatesFrom
之前不会释放它。