非同期Webサービスを呼び出すのに役立つNSURLCONNECTIONを試してください
NSURLConnection オブジェクトは、HTTP を使用して Web サービスを実行するために使用されます。NSURLConnection を使用する場合、リクエストは非同期形式で行われます。これは、リクエストの終了を待たずに続行することを意味します。
このデリゲートは、次のメソッドを実装する必要があります。
connection:didReceiveResponse : called after the connection is made successfully and before receiving any data. Can be called more than one time in case of redirection.
connection:didReceiveData : called for each bloc of data.
connectionDidFinishLoading : called only one time upon the completion of the request, if no error.
connection:didFailWithError : called on error.
例: -
NSData *data = [[NSMutableData alloc] init];
NSURL *url_string = [NSURL URLWithString:
@"Your URL"];
NSURLRequest *request = [NSURLRequest requestWithURL:url_string];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
if (!conn) {
// this is better if you @throw an exception here
NSLog(@"error while starting the connection");
[data release];
}
受信した生データのブロックごとに、このメソッドでここにデータを追加できます。
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)someData {
[data appendData:someData];
}
connectionDidFinishLoading
正常に受信されたデータの最後に呼び出されます