4

アプリの読み込み中に、NSUserDedaults ディクショナリでいくつかの操作を実行します。一部のユーザーでは、次のロジックでアプリがクラッシュします。

NSUserDefaults* prefs = [NSUserDefaults standartUserDefaults];
NSString* nsKey = [NSString stringWithUTF8String:ket.c_str()];

[prefs removeObjectForKey:nsKey];
[prefs synchronize];

クラッシュは最後の行で発生します (同期)。理由がわかりません。私には起こりません。

何か案は?

編集::

This is the crash:

0   CoreFoundation                      0x34d02e58 CFRetain + 20
1   CoreFoundation                      0x34d0a9bf _CFArrayReplaceValues + 235
2   CoreFoundation                      0x34d0f0e5 CFArrayAppendValue + 125
3   CoreFoundation                      0x34d26d57 _flattenPlist + 139
4   CoreFoundation                      0x34d26dbd _flattenPlist + 241
5   CoreFoundation                      0x34d6e08f __CFBinaryPlistWrite + 127
6   CoreFoundation                      0x34d26cad CFPropertyListWrite + 429
7   CoreFoundation                      0x34d26aa5 CFPropertyListWriteToStream + 221
8   CoreFoundation                      0x34d25fc1 _CFXPreferencesWritePlist + 273
9   CoreFoundation                      0x34d25ead -[CFXPreferencesPropertyListSourceSynchronizer writePlistToDisk] + 129
10  CoreFoundation                      0x34d22699 -[CFXPreferencesPropertyListSourceSynchronizer synchronizeAlreadyFlocked] + 601
11  CoreFoundation                      0x34d2243d -[CFXPreferencesPropertyListSourceSynchronizer synchronize] + 21
12  CoreFoundation                      0x34d31b3b -[CFXPreferencesPropertyListSource synchronize] + 111
13  CoreFoundation                      0x34d32b93 -[CFXPreferencesSearchListSource synchronize] + 75
14  CoreFoundation                      0x3719d87f CFArrayRemoveAllValues + 122
15  CoreFoundation                      0x3719e1f1 CFRunLoopTimerIsValid + 36
16  libdispatch.dylib                   0x3435c7e7 __func__.16042 + 2384
17  libdispatch.dylib                   0x3435c647 __func__.16042 + 1968
18  libdispatch.dylib                   0x3435c267 __func__.16042 + 976
19  libdispatch.dylib                   0x3435c911 __func__.16042 + 2682
20  CoreFoundation                      0x34d39c67 CFPreferencesAppSynchronize + 335
21  Foundation                          0x32c4c8ef -[ABMultiCellContentView_Address tagForPropertyKey:] + 30
4

1 に答える 1

2

このように試してみてください:

NSString* nsKey = [NSString stringWithUTF8String:ket.c_str()];
if([[NSUserDefaults standardUserDefaults] stringForKey:nsKey] != nil)
{
    [[NSUserDefaults standartUserDefaults] removeObjectForKey:nsKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
于 2012-07-26T22:48:27.660 に答える