gpt4 book ai didi

ios - 同步 NSUserDefaults 时崩溃

转载 作者:行者123 更新时间:2023-12-01 22:29:06 27 4
gpt4 key购买 nike

当我尝试保存 NSUserDefaults 时,我的应用程序遇到了随机错误。任何帮助/建议将不胜感激!我四处搜寻但没有找到任何解决方案:|

在保存 NSuserDefaults 之前,我设置了 3 个值:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kInitialized];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kIsOK];
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:kInitDate];
[[NSUserDefaults standardUserDefaults] synchronize];

这是崩溃日志:

Thread 11 Crashed:
0 libsystem_kernel.dylib 0x383361f0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x383a0792 pthread_kill + 54
2 libsystem_c.dylib 0x382e7032 __abort + 74
3 libsystem_c.dylib 0x382e6fe4 abort + 84
4 libsystem_malloc.dylib 0x383656f4 szone_error + 312
5 libsystem_malloc.dylib 0x38365974 free_list_checksum_botch + 24
6 libsystem_malloc.dylib 0x3835fe02 small_malloc_from_free_list + 190
7 libsystem_malloc.dylib 0x3835cefa szone_malloc_should_clear + 1394
8 libsystem_malloc.dylib 0x3835c952 malloc_zone_malloc + 70
9 CoreFoundation 0x2d51026c __CFBasicHashRehash + 324
10 CoreFoundation 0x2d5116e4 __CFBasicHashAddValue + 96
11 CoreFoundation 0x2d42bff0 CFBasicHashAddValue + 3308
12 CoreFoundation 0x2d42c696 CFDictionaryAddValue + 178
13 CoreFoundation 0x2d440c1c _flattenPlist + 164
14 CoreFoundation 0x2d440ca2 _flattenPlist + 298
15 CoreFoundation 0x2d4a48da __CFBinaryPlistWrite + 126
16 CoreFoundation 0x2d440a48 CFPropertyListWrite + 240
17 CoreFoundation 0x2d450dd4 CFPropertyListWriteToStream + 140
18 CoreFoundation 0x2d44ea5c _CFXPreferencesWritePlist + 264
19 CoreFoundation 0x2d44e94c -[CFXPreferencesPropertyListSourceSynchronizer writePlistToDisk] + 124
20 CoreFoundation 0x2d44c1aa -[CFXPreferencesPropertyListSourceSynchronizer synchronizeAlreadyFlocked] + 482
21 CoreFoundation 0x2d44bfc0 -[CFXPreferencesPropertyListSourceSynchronizer synchronize] + 16
22 CoreFoundation 0x2d45d25e -[CFXPreferencesPropertyListSource synchronize] + 106
23 CoreFoundation 0x2d45da9a -[CFXPreferencesSearchListSource synchronize] + 70
24 CoreFoundation 0x2d4eb7ba ___CFXPreferencesAppSynchronize_block_invoke + 26
25 CoreFoundation 0x2d4ec122 ____CFXPREFS_SYNC_LOCKED_block_invoke + 30
26 libdispatch.dylib 0x3825b81c _dispatch_client_callout + 20
27 libdispatch.dylib 0x382617c6 _dispatch_barrier_sync_f_invoke + 22
28 CoreFoundation 0x2d4668b8 CFPreferencesAppSynchronize + 260
29 Foundation 0x2de516ec -[NSUserDefaults(NSUserDefaults) synchronize] + 20

更新:我已将 setValue 替换为 setObject 并继续观察我的应用程序。我会尽快向您报告此更正是否可以。

最佳答案

对于 NSUserDefaults,您应该使用 setObject:forKey:,而不是 setValue:forKey:。这可能是导致崩溃的原因,但即使它没有导致崩溃,您也需要更改它。

关于ios - 同步 NSUserDefaults 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com