アプリのメイン関数でエラーが発生します。NSURLConnection を同期させようとしました。このコードをメイン同期にするにはどうすればよいですか? コードは次のとおりです (サポート ファイルの main.m):
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
NSUrlConnection のコード:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *soapMessage = [NSString stringWithFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><m:GetRoomList xmlns:m=\"http://http://port number/WebService.svc/\"><departId xsi:type=\"xsd:int\">0</departId><roomID xsi:type=\"xsd:int\">0</roomID></m:GetRoomList></SOAP-ENV:Body></SOAP-ENV:Envelope>"];
NSURL *url=[NSURL URLWithString:@"http://port number/WebService.svc/"];
NSMutableURLRequest *theRequest= [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/WebService.svc" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue:@"port number" forHTTPHeaderField:@"Host"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse* response = nil;
NSData* data =[NSURLConnection sendSynchronousRequest: theRequest returningResponse: &response error: nil];
//self.theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
if (data) {
NSLog(@"%@",data);
} else {
NSLog(@"Failed");
}
}