【发布时间】:2012-04-18 00:58:17
【问题描述】:
我已经看过NSURLConnectionDelegate connection:didReceiveData not working,但似乎没有任何好的结果,所以我很好奇为什么我无法获得任何数据。
我在didReceiveResponse 和didReceiveData 中设置了断点。
它确实打印出“连接成功”,所以我知道连接已启动。
我正在使用 ARC 进行内存管理。
- (void)load {
request = [NSMutableURLRequest requestWithURL:myURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
[conn start];
NSLog(@"connection succeeded, %s", [myURL description]);
responseData = [NSMutableData data];
} else {
NSLog(@"connection failed");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
更新:
要了解我是如何测试这个的,请查看Asynchronous unit test not being called by SenTestCase。
我确实实现了 jonkroll 提到的两种方法,在他的回答中,我只是没有显示它们,但是它们也没有被调用。
我添加 [conn start] 只是因为它不起作用,我希望这可以解决它,但没有这样的运气。
【问题讨论】:
标签: ios5 asynchronous