0
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"ht...y.php"]];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat: @"User=A&Pass=1"];
[request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSHTTPURLResponse *urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

dispatch_async(kBgQueue, ^{
NSData* data2 = [NSData dataWithContentsOfURL: notyURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data2 waitUntilDone:YES];});

data2 ではなく data を使用するように dispatch_async を取得するにはどうすればよいですか?

4

1 に答える 1

1

sendSynchronousRequestとを使用する代わりに、次のようdispatch_asyncに NSURLConnection クラスのメソッドを使用することをお勧めしsendAsynchronousRequestます。

[NSURLConnection sendAsynchronousRequest:request 
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];

}];
于 2012-07-25T06:45:13.803 に答える