我想问你关于NSURLConnection
iPhone的objective-c。
我有一个应用程序需要连接到一个网络服务来接收数据(关于 YouTube 视频),然后我有我需要连接的所有东西(类似于网络中的 Hello_Soap 示例代码)。
但是现在,我的问题是我创建了一个NSObject
名为的类(继承自 ),Connection
并且我已经实现了方法:
didReceiveResponse
、和. 还有方法:didReceiveData
didFailWithError
connectionDidFinishLoading
-(void)Connect:(NSString *) soapMessage{
NSLog(soapMessage);
NSURL *url = [NSURL URLWithString:@"http://....."];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}
但是当我从我的 AppDelegate 创建一个Connection
对象时:
Connection * connect = [[Connection alloc] Init:num]; //It's only one param to test.
[connect Connect:method.soapMessage];
我调用这个方法,当它完成时,它不会继续调用didReceiveResponse
,或. 我正在尝试这样做,但我暂时做不到。didReceiveData
didFailWithError
connectionDidFinishLoading
我想做的事情是能够在每次我想接收数据时调用这个类“连接”(之后被解析并显示在UITableView
s 中)。
谢谢你。