UIWebView的一个简单实现

来源:互联网 发布:appstore付费软件 编辑:程序博客网 时间:2024/04/30 10:19

@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];}
0 0
原创粉丝点击