私はそのようにNSURLConnection
経由して使用しようとします...sendAsynchronousRequest
NSOperationQueue *myQueue = [[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:request queue:myQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
//do something
}];
ハンドラー ブロックが起動されたときにコンテンツがあることは、ほとんど自明です。
別のオプションは、NSURLConnectionDataDelegate
. URL を呼び出すと、処理が完了したことを知らせるいくつかのメソッドが起動されます。
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
//Fired on error
}
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
//Fired First
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//Fired Second
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//Fired Third
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//Fired Fourth
}
デリゲート メソッドを使用すると、didReceiveData
すぐにデータを取得できるようになります。幸運を。