我一直在被动地使用这个网站并阅读了常见问题解答,所以我希望我能够将这些内容保持在最低限度。
我对 Objective-C 中的 Settings.bundle 文件有疑问。我一直在使用以下指南来实现其中之一:
我同时使用 Xcode 4.1 和最新的 Xcode 3。我使用版本 3 创建 Settings.bundle 及其 plist,因为我发现 Xcode 4 的 plist 编辑器有些错误。
这些是我的 Root.plist 的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Authentication</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>User ID</string>
<key>Key</key>
<string>user_id_key</string>
<key>DefaultValue</key>
<string>1234</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>Alphabet</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
我可以毫无问题地访问 iOS 设置菜单中的设置,还可以更改我目前拥有的单个条目的值。该值存储在 iOS 模拟器以及我的物理 iOS 设备(iPhone 4)上的会话之间。
然而,我似乎无法从我的代码中访问这个值。让我向您展示我是如何尝试实现它的(在我的应用程序的 ViewController.m 中):
- (void)viewDidLoad
{
[super viewDidLoad];
myDefaults = [NSUserDefaults standardUserDefaults];
// DEBUG
userID = [myDefaults stringForKey:@"user_id_key"];
// userID = [NSString stringWithString:@"1234"];
// DEBUG
jsonBackendURL = @"http://example.com/jsonBackend.php";
passphrase = @"secretPassphrase";
theURLConnectionController = [[URLConnectionController alloc] initWithCallerObject:self];
[theURLConnectionController getConnectionAndUpdate:NO];
}
奇怪的是,当我尝试在 Xcode 3 中运行该应用程序时,我既没有收到任何错误消息(如 SIGABRT 等),也没有收到任何调试器输出。iPhone模拟器的屏幕在尝试启动应用程序时变黑了一会儿,然后我被带回主屏幕。
Xcode 4 显示了一些相当奇怪的行为。它设法显示我的应用程序的 UI 一两秒钟,然后带我回到 iPhone 模拟器的主屏幕。它还表明 SIGABRT 在我的代码中更远的地方,我尝试从 JSON 响应中获取值:
NSString *arrivalToday = [NSString stringWithString:[jsonResponse objectForKey:@"from"]];
由于 JSON 字符串是由 PHP 脚本使用我的应用程序传入的 GET 参数生成的 - 其中之一是来自 Settings.bundle 的用户 ID - 这不应该起作用也就不足为奇了。但是它不应该崩溃,因为我在代码中早些时候发现了这个错误,但这可能与我的设置问题无关。不过,真正令人头疼的是 Xcode(有点)在 iPhone 模拟器中与我的应用程序一起崩溃。首先,Xcode 一直正常工作,只是我无法中止似乎仍在运行的程序。我可以单击 Xcode 中的停止按钮,但没有效果。当我尝试退出 Xcode 时,它会询问我是否应该终止正在运行的程序,当我单击“是”时,它会真正崩溃,我必须强制退出它。
不过幸运的是,Xcode 4 为我提供了我的应用程序的调用堆栈:
2011-07-21 11:41:04.539 OneClickCheckIn[2098:b303] http://example.com/json.php?user=(null)&pass=secretPassphrase&getStartToday
2011-07-21 11:41:04.888 OneClickCheckIn[2098:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'
*** Call stack at first throw:
(
0 CoreFoundation 0x00de25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f36313 objc_exception_throw + 44
2 CoreFoundation 0x00d9aef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d9ae6a +[NSException raise:format:] + 58
4 Foundation 0x007ca14c -[NSPlaceholderString initWithString:] + 105
5 Foundation 0x007d3266 +[NSString stringWithString:] + 72
6 OneClickCheckIn 0x00002b5c -[OneClickCheckInViewController updateInterfaceWithJsonResponse:] + 172
7 OneClickCheckIn 0x0000e82c -[URLConnectionControllerDelegate connectionDidFinishLoading:] + 364
8 Foundation 0x007de112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
9 Foundation 0x007de06b _NSURLConnectionDidFinishLoading + 133
10 CFNetwork 0x030fa48e _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
11 CFNetwork 0x031c56e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
12 CFNetwork 0x031c59cf _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1043
13 CFNetwork 0x030f0c80 _ZN19URLConnectionClient13processEventsEv + 100
14 CFNetwork 0x030f0acf _ZN17MultiplexerSource7performEv + 251
15 CoreFoundation 0x00dc38ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x00d2188b __CFRunLoopDoSources0 + 571
17 CoreFoundation 0x00d20d86 __CFRunLoopRun + 470
18 CoreFoundation 0x00d20840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00d20761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x0101a1c4 GSEventRunModal + 217
21 GraphicsServices 0x0101a289 GSEventRun + 115
22 UIKit 0x00042c93 UIApplicationMain + 1160
23 OneClickCheckIn 0x00002609 main + 121
24 OneClickCheckIn 0x00002585 start + 53
25 ??? 0x00000001 0x0 + 1
)
terminate called throwing an exception(lldb)
这就是我现在想到的所有相关信息。我已经对 Google 进行了广泛的研究,并且还阅读了该站点上的一些主题,但我找不到解决方案。