我试图四处寻找答案,但没有找到适合我的解决方案。
我要做的就是正确设置我的 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);
}