【发布时间】:2016-08-05 05:26:45
【问题描述】:
我正在使用 iMessage 气泡来创建正常工作的聊天视图
https://github.com/kerrygrover/iMessageBubble
当我在我的内部方法中调用我的网络服务时
- (IBAction)sendMessage:(id)sender
这是我的网络方法调用函数,它给出了结果输出成功并将我的聊天发送到服务器,但我的视图冻结了。
NSError *errorReturned = nil;
NSString *urlString = @"https://url/methodname”;
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:employeeId forKey:@"employeeId"];
[dict setObject:employeename forKey:@"employeename"];
NSLog(@"dic=%@",dict);
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:&errorReturned];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: jsonData];
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned)
{
//...handle the error
}
else
{
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseString);
//...do something with the returned value
}
}
【问题讨论】:
标签: objective-c iphone xcode ios8