崩溃:com.apple.root.background-qos SIGABRT ABORT 0x000000018373d2ec

时间:2018-05-28 10:16:41

标签: ios objective-c nscalendar

应用程序在发布时崩溃。它不会每次都崩溃。执行以下代码来初始化NSCalendar对象并用于日期和时间计算。

static NSCalendar *calendar;
+(NSCalendar*)getCalendar {
    if (calendar == nil) {
        calendar = [NSCalendar currentCalendar];
        [calendar setFirstWeekday:1];
        [calendar setMinimumDaysInFirstWeek:1];
    }
    return calendar;
}

有时会在行[calendar setFirstWeekday:1]或[calendar setMinimumDaysInFirstWeek:1]中观察到崩溃;

Crashed: com.apple.root.background-qos
0  libsystem_kernel.dylib         0x18373d2ec __pthread_kill + 8
1  libsystem_pthread.dylib        0x1838de288 pthread_kill$VARIANT$mp + 376
2  libsystem_c.dylib              0x1836abd0c abort + 140
3  libc++abi.dylib                0x182e472c8 __cxa_bad_cast + 130
4  libc++abi.dylib                0x182e47470 default_unexpected_handler() + 302
5  libobjc.A.dylib                0x182e708d4 _objc_terminate() + 124
6  libc++abi.dylib                0x182e6137c std::__terminate(void (*)()) + 16
7  libc++abi.dylib                0x182e60f78 __cxa_rethrow + 144
8  libobjc.A.dylib                0x182e707ac objc_exception_rethrow + 44
9  CoreFoundation                 0x183cceb44 -[_NSCopyOnWriteCalendarWrapper setMinimumDaysInFirstWeek:] + 152
10 myapp                          0x104fc81e4 +[Utils getCalendar] (Utils.m:405)
11 myapp                          0x104fc8504 +[Utils dateByAddingUnit:value:toDate:] (Utils.m:474)
12 myapp                          0x104f1218c +[LocalNotificaitonUtils cancelAndScheduleNotificationWithType:message:delta:category:] (LocalNotificaitonUtils.m:355)
13 libdispatch.dylib              0x1835a8b24 _dispatch_call_block_and_release + 24
14 libdispatch.dylib              0x1835a8ae4 _dispatch_client_callout + 16
15 libdispatch.dylib              0x1835b5e80 _dispatch_root_queue_drain + 924
16 libdispatch.dylib              0x1835b5a80 _dispatch_worker_thread3 + 120
17 libsystem_pthread.dylib        0x1838dbfac _pthread_wqthread + 1176
18 libsystem_pthread.dylib        0x1838dbb08 start_wqthread + 4

1 个答案:

答案 0 :(得分:0)

我认为如果删除静态实例并且只是引用currentCalendar:

,这种崩溃可能会消失
+(NSCalendar*)getCalendar {
 NSCalendar *calendar = [NSCalendar currentCalendar];
 [calendar setFirstWeekday:1];
 [calendar setMinimumDaysInFirstWeek:1];
 return calendar;
}