ios - 命名空间 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
我该如何处理此异常以避免将来出现此问题。
解决方案
跟进评论讨论,并且不需要此答案指示(根据 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% 清楚,我不能保证这会解决这个特定的崩溃问题,但作为一个非常省力的修复候选者,值得尝试。
推荐阅读
- c# - 通知游戏对象更改的最佳方式?(统一脚本组织/委托)
- python - 在 Python 中重新启动程序
- django - django UserCreationForm() 附加的模型是什么
- python-3.x - 理解和使用共指解析斯坦福 NLP 工具(在 Python 3.7 中)
- java - Intellij Idea 在运行以下程序时显示错误:-
- python-3.x - Python合并重复,求和和乘法
- java - 如何在 Apache Beam 中使用 AvroCoder 注释对 Joda DateTime 进行编码?
- python - 艺术风格转移:ValueError:浮点图像 RGB 值必须在 0..1 范围内。使用 pytorch
- python - 如何动态更改 Keras 的后端?
- python - 无法在 Apache、WSGI、Django 和 Windows 中加载虚拟环境