我正在尝试拨打网络服务,但不幸的是我的电话没有录制,我不确定为什么会这样做......
这是我正在使用的代码,也许我错过了一些东西:
NSURL *URL = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
我需要做的就是能够加载网页,而不必在safari或web视图中加载它
谢谢!
答案 0 :(得分:0)
NSURL *url = [NSURL URLWithString:webService];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection) {
//webData = [[NSMutableData data] retain];
}else {
NSLog(@"The Connection is NULL");
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
webData = [[NSMutableData data] retain];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
答案 1 :(得分:0)
结帐this tutorial,了解如何与iOS中的网络服务建立联系。它并不像进行连接那么简单。