2012-11-16 57 views
0

崩潰時在線路:的iOS 6應用程序崩潰請求訪問日曆

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

崩潰消息會幫助很多,如果你想讓人們引導你 – Olotiar

+0

添加屏幕截圖,thx – 1337code

+0

嘿我得到同樣的問題,你的解決方案是什麼。我使用ARC所以釋放不是爲GCD.Let我知道,請欣賞.. – Sabby

回答

0

檢查eventStoreQueue是否被有效創建:

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

如果是,請確保在輸入presentingDatesFrom之前不會隨時釋放。

相關問題