答えを探してみましたが、自分に合った解決策が見つかりませんでした。
私がやろうとしているのは、NSURLConnection を正しくセットアップすることだけです。doSomethingTwo() を呼び出すと、didReceiveResponse と didReceiveData から出力が得られますが、didFailWithError や connectionDidFinishLoading からは出力されません。私が行方不明になっていることを他に何かする必要がありますか?
これが私のコードです:
- (void) doSomethingTwo: (CCMenuItem *) menuItem
{
NSLog(@"The second menu was called");
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://theholyroller.net/iphone/index.php"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
NSLog(@"Received Response");
[self.responseData setLength:0];
}
- (void) connection:(NSURLConnection *) connection didReceiveData:(NSData *)data {
NSLog(@"Received Data");
NSLog(@"%@", data);
[self.responseData appendData:data];
}
- (void) connection:(NSURLConnection *) connection didFailWithError:(NSError *)error {
NSLog(@"Failed with error");
}
- (void) connectionDidFinishloading:(NSURLConnection *)connection {
NSLog(@"Finished Loading");
NSLog(@"%@", self.responseData);
}