如何进行UIApplicationMain同步

时间:2013-05-30 07:30:49

标签: ios sync

我的应用程序在主要功能中给我错误。我试图使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");
    }
}

1 个答案:

答案 0 :(得分:-1)

当iOS应用程序崩溃Xcode显示此行时,但错误不在此处。 显示NSURLConnection的代码

相关问题