【发布时间】:2013-07-20 18:36:48
【问题描述】:
NSString *post = [NSString stringWithFormat:@"email=%@",_benimEmail];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURLURLWithString:@"http://localhost:8888/iphone/msg.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error; NSURLResponse *response;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *veri = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",veri);
上面的代码是在点击按钮时运行的,它将查询一个网络服务。
现在,当我单击按钮时,应用程序会冻结一段时间。我怎样才能防止这种情况发生?
【问题讨论】:
标签: ios objective-c foundation