我正在使用这段代码:
NSString *recievedData;
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.site.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
recievedData = [NSMutableData data];
NSLog(@"%@", recievedData);
} else {
// Inform the user that the connection failed.
NSLog(@"Unsuccessful.");
}
这是这个的修改版本。
我的问题是它总是返回
<>
无论我是否连接到互联网,它总是会成功。