您的位置:首页 > 移动开发

UIWebView的一个简单实现

2016-05-17 14:50 465 查看
@property(weak,nonatomic) UIWebView *webView;

//确定一个要访问的资源
NSURL *url = [NSURL URLWithString:@"http://m.baidu.com"];
//建立请求,准备告诉服务器端,我们客户端需要的资源
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:url];
//表明自己的设备属性以返回对应数据
[request setValue:@"Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like MacOS X) AppleWebKit/600.1.4 (KHTML, like Gecko)" forHTTPHeaderField:@"User-Agent"];
//把请求发送给服务器,等处理完后,返回数据
[NSURLConnection sendAsynchoronousRequest:request queue:
[[NSOperationQueue alloc] init] completionHandler:
^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
NSString *heml = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[self.webView loadHTMLString:html baseURL:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uiwebview