某些 JSON 请求在 adHoc 上崩溃,但在调试时不会崩溃
我正在使用 json-framework 与某些 Web 服务进行通信。到目前为止,它对我很有帮助。但是,此代码会使设备上的临时应用程序崩溃。设备上调试模式下的同一应用程序运行正常。
这是我的 JSON 请求(这就是它崩溃的地方):
//Make values dictionary
NSMutableDictionary *valuesDictionary;
NSMutableDictionary *valuesDictionary_1;
NSMutableArray *tempArray;
NSMutableArray *values = [[NSMutableArray alloc] init];;
NSEnumerator * enumerator = [self.contactsTempArray objectEnumerator];
id tempObj;
while ( tempObj = [enumerator nextObject] ) {
valuesDictionary = [[NSMutableDictionary alloc] init];
valuesDictionary_1 = [[NSMutableDictionary alloc] init];
tempArray = [[NSMutableArray alloc] init];
//NSString *key = [NSString stringWithFormat:]
if([[tempObj objectForKey:@"Checked"] isEqualToString:@"1"]) {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:true] forKey:@"IsEnabled"];
}
else {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:false] forKey:@"IsEnabled"];
}
[tempArray addObject:valuesDictionary];
[tempArray addObject:valuesDictionary_1];
[values addObject:valuesDictionary];
[valuesDictionary release];
}
//UPDATE NOTIFICATIONS SETTINGS
//JSON POST request
NSArray *keys = [NSArray arrayWithObjects:@"sessionId", @"apiKey", @"deviceToken", @"values", nil];
NSArray *objects = [NSArray arrayWithObjects:appDelegate.sessionId, appDelegate.apiKey, appDelegate.deviceToken, values, nil];
NSDictionary *getAllSensorsDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *requestString = [NSString stringWithFormat:@"%@", [getAllSensorsDict JSONFragment], nil];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://xxxxxxxxx"]];
[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: requestData];
//JSON response
NSData *jsonData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
有什么想法我做错了什么吗?
JSON 请求对于 adHoc 来说是否太复杂?
I am using json-framework for communication purposes with certain web service. So far it has served me well. However, this code crashes my adHoc app on the device. The same app in debug mode on the device works ok.
Here is my JSON request(that is where it crashes):
//Make values dictionary
NSMutableDictionary *valuesDictionary;
NSMutableDictionary *valuesDictionary_1;
NSMutableArray *tempArray;
NSMutableArray *values = [[NSMutableArray alloc] init];;
NSEnumerator * enumerator = [self.contactsTempArray objectEnumerator];
id tempObj;
while ( tempObj = [enumerator nextObject] ) {
valuesDictionary = [[NSMutableDictionary alloc] init];
valuesDictionary_1 = [[NSMutableDictionary alloc] init];
tempArray = [[NSMutableArray alloc] init];
//NSString *key = [NSString stringWithFormat:]
if([[tempObj objectForKey:@"Checked"] isEqualToString:@"1"]) {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:true] forKey:@"IsEnabled"];
}
else {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:false] forKey:@"IsEnabled"];
}
[tempArray addObject:valuesDictionary];
[tempArray addObject:valuesDictionary_1];
[values addObject:valuesDictionary];
[valuesDictionary release];
}
//UPDATE NOTIFICATIONS SETTINGS
//JSON POST request
NSArray *keys = [NSArray arrayWithObjects:@"sessionId", @"apiKey", @"deviceToken", @"values", nil];
NSArray *objects = [NSArray arrayWithObjects:appDelegate.sessionId, appDelegate.apiKey, appDelegate.deviceToken, values, nil];
NSDictionary *getAllSensorsDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *requestString = [NSString stringWithFormat:@"%@", [getAllSensorsDict JSONFragment], nil];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://xxxxxxxxx"]];
[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: requestData];
//JSON response
NSData *jsonData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
any ideas what am I doing wrong?
Is the JSON request too complex for adHoc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的 iPhone 连接到您的 Mac。然后打开 xcode,打开菜单、窗口、管理器。转到“崩溃日志”并查看有关崩溃的信息...
或者您甚至可以使用“构建并运行”按钮在 iPhone(连接到 Mac)中测试您的应用程序。您将在控制台中看到崩溃消息。
Connect your iphone to your mac. Then open xcode, open menu, window, organizer. There go to "crash logs" and look the info about the crash....
Or you can even test your app in your iphone (connected to the mac) using the Build and Go button. You will see the crash messages in the console.