NSURLResponse 在模拟器中很快出现,但在实际设备上它会在一段时间后出现或 returns NULL

NSURLResponse comes quickely in Simulator but on actual Device it comes after some time or returns NULL

我正在创建一个在每个视图上调用 Web 服务的应用程序-controller.The 应用程序在模拟器上运行良好,但在实际设备上,它运行非常缓慢,有时甚至 returns 空响应,这就是应用程序的原因由于 sever.Is 的空响应而崩溃 有任何解决方案可以解决此问题 issue.I 我对 objective-c 很陌生 programming.Please 建议我解决问题的方法。非常感谢。:)

我在这里添加了我的代码部分,它向网络服务发送请求并接收响应。

{
    NSURL *url = [NSURL URLWithString:@"http://www.someurl.com/somewebservice.asmx"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    [theRequest addValue:@"somehost.in" forHTTPHeaderField:@"Host"];
    [theRequest addValue:@"someUrl/someWebMethod" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Type"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection =
    [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    NSURLResponse *response1 = [[NSURLResponse alloc] init];;
    self.webResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

    self.response = [[NSURLResponse alloc] init];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"Printing response...\n");
    NSLog(@"%@",response);
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [self.webResponseData  appendData:data];
}

您正在使用 sendSynchronousRequest。不。从不,从不,从不在主线程上同步网络。