NSURLConnection
iPhone用のobjective-cについてお聞きしたいのですが。
データ(YouTubeビデオに関する)を受信するために1つのWebサービスに接続する必要がある1つのアプリがあり、次に接続する必要があるすべてのものがあります(Webの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から1つのConnection
オブジェクトを作成する場合:
Connection * connect = [[Connection alloc] Init:num]; //It's only one param to test.
[connect Connect:method.soapMessage];
そして、私はこのメソッドを呼び出します。これが終了すると、、、、またはの呼び出しは続行さdidReceiveResponse
れdidReceiveData
ませdidFailWithError
んconnectionDidFinishLoading
。私はこれをやろうとしていますが、今のところできません。
私がやりたいのは、データを受信するたびにこのクラスを「接続」と呼べるようにすることです(その後、解析してUITableView
sに表示します)。
ありがとうございました。