首页 > 解决方案 > 命名空间 SIGNAL,代码 0x5,带有 EXC_BREAKPOINT (SIGTRAP)

问题描述

我无法重现该问题。我的一位用户发送了崩溃日志,问题似乎指向 NSUserDefault setBool:forKey 方法。

不适用于用户设备 iPhone 6,iOS 版本:12.4.4。由于应用程序崩溃,目前仅联系了一位用户。

在我测试过的设备上工作。(iPad Air 2、iPhone XS、iOS 13.3 版)

这是我正在使用的方法。

- (void) saveToDefaults:(NSString*)productId
{        
    [ [ NSUserDefaults standardUserDefaults ] setBool:YES forKey:productId ];
    [ [ NSUserDefaults standardUserDefaults ] synchronize];
}

崩溃转储

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000020eae32e4
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [15897]
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   CoreFoundation                  0x000000020eae32e4 CFHash + 372 (CFRuntime.c:1147)
1   CoreFoundation                  0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
2   CoreFoundation                  0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
3   CoreFoundation                  0x000000020eaada40 CFDictionaryGetValue + 120 (CFDictionary.c:413)
4   CoreFoundation                  0x000000020eaca938 -[CFPrefsSearchListSource alreadylocked_setPrecopiedValues:forKeys:count:from:] + 496 (CFPrefsSearchListSource.m:632)
5   CoreFoundation                  0x000000020eb81230 -[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:] + 372 (CFPrefsSource.m:742)
6   CoreFoundation                  0x000000020eb81524 -[CFPrefsSource setValues:forKeys:count:copyValues:from:] + 36 (CFPrefsSource.m:766)
7   CoreFoundation                  0x000000020ea3e3dc -[CFPrefsSource setValue:forKey:from:] + 64 (CFPrefsSource.m:772)
8   CoreFoundation                  0x000000020eaccc54 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurat... + 272 (CFPrefsSearchListSource.m:1553)
9   CoreFoundation                  0x000000020eacc698 normalizeQuintuplet + 340 (CFPrefsSearchListSource.m:63)
10  CoreFoundation                  0x000000020ea3ad64 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationUR... + 108 (CFPrefsSearchListSource.m:1433)
11  CoreFoundation                  0x000000020ea3dd7c -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 92 (CFXPreferences.m:759)
12  CoreFoundation                  0x000000020eb8b360 _CFPreferencesSetAppValueWithContainerAndConfiguration + 132 (CFXPreferences.m:1867)
13  Foundation                      0x000000020f4eb3b8 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 64 (NSUserDefaults.m:228)
14  MyApp                           0x00000001004adb14 -[IAPHelper saveToDefaults:] + 88 (IAPHelper.m:206)
15  MyApp                           0x00000001004adc3c -[IAPHelper restoreTransaction:] + 224 (IAPHelper.m:223)
16  MyApp                           0x00000001004ad928 -[IAPHelper paymentQueue:updatedTransactions:] + 264 (IAPHelper.m:0)
17  libdispatch.dylib               0x000000020e58ca38 _dispatch_call_block_and_release + 24 (init.c:1372)
18  libdispatch.dylib               0x000000020e58d7d4 _dispatch_client_callout + 16 (object.m:511)
19  libdispatch.dylib               0x000000020e53b008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068 (inline_internal.h:2441)
20  CoreFoundation                  0x000000020eae0b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1813)
21  CoreFoundation                  0x000000020eadba58 __CFRunLoopRun + 1924 (CFRunLoop.c:3113)
22  CoreFoundation                  0x000000020eadafb4 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
23  GraphicsServices                0x0000000210cdc79c GSEventRunModal + 104 (GSEvent.c:2245)
24  UIKitCore                       0x000000023b33cc38 UIApplicationMain + 212 (UIApplication.m:4353)
25  MyApp                           0x00000001004e9cec main + 88 (main.m:14)
26  libdyld.dylib                   0x000000020e59e8e0 start + 4

我该如何处理此异常以避免将来出现此问题。

标签: iosobjective-cxcodeexception

解决方案


跟进评论讨论,并且不需要此答案指示(根据 Apple 的 iOS 12 发行说明):synchronize

我的目标 iOS 是 11.2,我想我现在不能使用它。

是的你可以。

在评论中总结我的建议:

if (@available(iOS 12, *)) {
   // don't need to synchronize
} else {
   [NSUserDefaults.standardUserDefaults synchronize];
}

上面的代码@available类 Swift 语法假设您使用的是 Xcode 9 或更高版本。鉴于目标 iOS 几乎是必须的。

只是为了让自己 100% 清楚,我不能保证这会解决这个特定的崩溃问题,但作为一个非常省力的修复候选者,值得尝试。


推荐阅读