123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // CYWebCustomerServiceVC.m
- // shiku_im
- //
- //
- //
- //
- #import "CYWebCustomerServiceVC.h"
- #import <WebKit/WebKit.h>
- @interface CYWebCustomerServiceVC ()<WKUIDelegate,WKNavigationDelegate>
- @property (nonatomic,strong)WKWebView *wkWebView;
- @end
- @implementation CYWebCustomerServiceVC
- //- (void)viewDidLoad {
- // [super viewDidLoad];
- // // Do any additional setup after loading the view.
- // self.heightHeader = JX_SCREEN_TOP;
- // self.heightFooter = 0;
- // self.isGotoBack = YES;
- // self.isShowHeaderPull = NO;
- // self.isShowFooterPull = NO;
- //// self.title = Localized(@"JX_PublicNumber");
- // self.title = self.titleName;
- // [self createHeadAndFoot];
- // // WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- // // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width, self_height) configuration:config];
- // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP , self_width, self_height - JX_SCREEN_TOP)];
- //// [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://e-135639.chatnow.meiqia.com/dist/standalone.html"]]];
- // [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.link]]];
- // [self.view addSubview:self.wkWebView];
- //}
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.heightHeader = JX_SCREEN_TOP;
- self.heightFooter = 0;
- self.isGotoBack = NO;
- // self.title = Localized(@"JX_PublicNumber");
- // self.title = @"开奖";
- self.title = self.titleName;
- [self createHeadAndFoot];
- // WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
- // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width, self_height) configuration:config];
- self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width,self_height- JX_SCREEN_TOP - JX_SCREEN_BOTTOM_SAFE_AREA)];
- [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.link]]];
- // [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://qs77888.com"]]];
- self.wkWebView.UIDelegate = self;
- self.wkWebView.navigationDelegate = self;
- [self.view addSubview:self.wkWebView];
- [self setupUI];
- }
- - (void)setupUI {
- UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
- label1.text = @"< 返回";
- UIBarButtonItem *lItem = [[UIBarButtonItem alloc] initWithCustomView:label1];
- [label1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftButtonClick)]];
- label1.userInteractionEnabled = YES;
- [self setLeftBarButtonItem:lItem];
- }
- - (void)leftButtonClick {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- // 根据WebView对于即将跳转的HTTP请求头信息和相关信息来决定是否跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
-
- NSString * urlStr = navigationAction.request.URL.absoluteString;
- NSLog(@"发送跳转请求:%@",urlStr);
- //自己定义的协议头
-
- decisionHandler(WKNavigationActionPolicyAllow);
-
-
- }
- // 根据客户端受到的服务器响应头以及response相关信息来决定是否可以跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
- NSString * urlStr = navigationResponse.response.URL.absoluteString;
- NSLog(@"当前跳转地址:%@",urlStr);
- //允许跳转
- decisionHandler(WKNavigationResponsePolicyAllow);
- //不允许跳转
- //decisionHandler(WKNavigationResponsePolicyCancel);
- }
- // 页面是弹出窗口 _blank 处理
- - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
- if (!navigationAction.targetFrame.isMainFrame) {
- [webView loadRequest:navigationAction.request];
- }
- return nil;
- }
- // 页面开始加载时调用
- - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
- [SVProgressHUD showWithStatus:@"正在加载中..."];
- }
- // 页面加载失败时调用
- - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
- [SVProgressHUD dismiss];
- }
- // 当内容开始返回时调用
- - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
- [SVProgressHUD dismiss];
- }
- // 页面加载完成之后调用
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
- [SVProgressHUD dismiss];
- }
- //提交发生错误时调用
- - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
- [SVProgressHUD dismiss];
- }
- // 接收到服务器跳转请求即服务重定向时之后调用
- - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
- [SVProgressHUD dismiss];
- }
- @end
|