块代码崩溃问题

时间:2016-06-01 05:57:43

标签: ios crash dispatch-async

我正在使用SDK并使用[[EventStore sharedEventStore] getEventsMatchingQuery:self.aEventQuery];来给我数组作为回报。事件虽然我给出了正确的参数,但它正在崩溃。是代码还是SDK中的问题?

    - (void)fetchMonthViewEventWithStartDate:(NSDate*)startDate withEndDate:(NSDate*)endDate {

    if (monthViewQueue ==nil) {
        monthViewQueue = dispatch_queue_create("monthView Queue",NULL);    
    }


    self.sDate = startDate;
    self.eDate = endDate;

    //    __weak __typeof(&*self)weakSelf = self;

    NSDate *eventStartDate = [NSDate getStartDateOfEventForDate:startDate];
    NSDate *eventEndDate = [NSDate getEndDateOfEventForDate:endDate];

    dispatch_async(monthViewQueue, ^{

        [[Manager SharedManager] fetchEventWithStartDate:eventStartDate withEndDate:eventEndDate withSuccessCallBack:^(BOOL success, NSMutableArray *mFilteredArray) {

            if(success)
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    _successBlock(mFilteredArray);
                });

            }else {
                 _successBlock(nil);
            }


        } onFailure:^(BOOL status) {

        } ifOffline:^(NSString *message) {

        }];

    });

}

- (void)fetchEventWithStartDate:(NSDate *)startDate withEndDate:(NSDate *)endDate
            withSuccessCallBack:(SuccessFetchEventsListCallback)success_callback onFailure:(FailureFetchEventsListCallback)failure_callback
                      ifOffline:(OfflineCallback)offlineCallback{

    [self.aEventQuery setStartDate:startDate];
    [self.aEventQuery setEndDate:endDate];
    NSArray <Calendar *>* cales = [[EventStore sharedEventStore] getCalendars]; // have calendar in db
    if ([cales count]>0) {
       [self.aEventQuery setCalendars:[[CalendarManager calendarSharedManager] getSelectedCalendars]];
    }

    //TODO: some time crash
    NSLog(@"aEventQuery - %@ %@",self.aEventQuery.getStartDate,self.aEventQuery.getEndDate);
    NSArray  *imcEvents = [[EventStore sharedEventStore] getEventsMatchingQuery:self.aEventQuery]; // crashing here


    if ([imcEvents count] == 0) {
        if (success_callback) {
            success_callback(NO,nil);
        }

        return;
    }

    NSPredicate *isAllDayPredicate = [NSPredicate predicateWithFormat:@"isAllDay== YES"];
    NSPredicate *isNonAllDayPredicate = [NSPredicate predicateWithFormat:@"isAllDay== NO"];

    NSArray *allDaysArray = [imcEvents filteredArrayUsingPredicate:isAllDayPredicate];

    NSArray *nonAllDaysArray = [imcEvents filteredArrayUsingPredicate:isNonAllDayPredicate];

    //    DLog(@"allDaysArray --> %@",allDaysArray);
    //    DLog(@"nonAllDaysArray --> %@",nonAllDaysArray);

    NSMutableArray *mResultArray = [NSMutableArray array];

    if ([allDaysArray count] != 0) {
        [mResultArray addObjectsFromArray:allDaysArray];
    }
    if ([nonAllDaysArray count] != 0) {
        [mResultArray addObjectsFromArray:nonAllDaysArray];
    }

    DLog(@"fetched imcEvents - %@",imcEvents);
    if (success_callback) {
        success_callback(YES,mResultArray);
    }
}

崩溃日志:

thread #11: tid = 0x151744, 0x0000000107bb39a0 libsqlite3.dylib`sqlite3ExprCodeTarget + 2064, queue = 'monthView Queue', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x0000000107bb39a0 libsqlite3.dylib`sqlite3ExprCodeTarget + 2064
    frame #1: 0x0000000107bb624e libsqlite3.dylib`sqlite3ExprCodeExprList + 270
    frame #2: 0x0000000107bc9e10 libsqlite3.dylib`selectInnerLoop + 528
    frame #3: 0x0000000107b9b8e5 libsqlite3.dylib`sqlite3Select + 9973
    frame #4: 0x0000000107b8657f libsqlite3.dylib`yy_reduce + 4191
    frame #5: 0x0000000107b8535f libsqlite3.dylib`sqlite3Parser + 127
    frame #6: 0x0000000107b3e4b5 libsqlite3.dylib`sqlite3RunParser + 501
    frame #7: 0x0000000107b84a61 libsqlite3.dylib`sqlite3Prepare + 529
    frame #8: 0x0000000107b3ce7f libsqlite3.dylib`sqlite3LockAndPrepare + 319
    frame #9: 0x0000000107b3cadb libsqlite3.dylib`sqlite3_prepare_v2 + 43
    frame #10: 0x0000000103b3fb4e CalApi`DBSession::runQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) + 1294
    frame #11: 0x0000000103b41774 CalApi`DBSession::loadFromDB(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 68
    frame #12: 0x0000000103b66a03 CalApi`EventStore::getAllCalendars() + 467
    frame #13: 0x0000000103ae3d3d CalApi`-[EventStore getCalendars] + 34
    frame #14: 0x0000000100ba8c11 -[Manager fetchEventWithStartDate:withEndDate:withSuccessCallBack:onFailure:ifOffline:](self=0x00007f904c492640, _cmd="fetchEventWithStartDate:withEndDate:withSuccessCallBack:onFailure:ifOffline:", startDate=2016-06-01 00:00:00 UTC, endDate=2016-06-02 00:00:00 UTC, success_callback=0x0000700000093cb8, failure_callback=0x0000000100eee060, offlineCallback=0x0000000100eee0a0) + 385 at Manager.m:165
    frame #15: 0x0000000100c7b36e `__85-[MonthViewTableListViewController fetchMonthViewEventWithStartDate:withEndDate:]_block_invoke(.block_descriptor=0x00007f904cbec3b0) + 238 at MonthViewTableListViewController.m:107
    frame #16: 0x00000001059bad9d libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #17: 0x00000001059db3eb libdispatch.dylib`_dispatch_client_callout + 8
    frame #18: 0x00000001059c182c libdispatch.dylib`_dispatch_queue_drain + 2215
    frame #19: 0x00000001059c0d4d libdispatch.dylib`_dispatch_queue_invoke + 601
    frame #20: 0x00000001059c3996 libdispatch.dylib`_dispatch_root_queue_drain + 1420
    frame #21: 0x00000001059c3405 libdispatch.dylib`_dispatch_worker_thread3 + 111
    frame #22: 0x0000000105d2f4f2 libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #23: 0x0000000105d2d375 libsystem_pthread.dylib`start_wqthread + 13

0 个答案:

没有答案