CYWebCustomerServiceVC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // CYWebCustomerServiceVC.m
  3. // shiku_im
  4. //
  5. //
  6. //
  7. //
  8. #import "CYWebCustomerServiceVC.h"
  9. #import <WebKit/WebKit.h>
  10. @interface CYWebCustomerServiceVC ()<WKUIDelegate,WKNavigationDelegate>
  11. @property (nonatomic,strong)WKWebView *wkWebView;
  12. @end
  13. @implementation CYWebCustomerServiceVC
  14. //- (void)viewDidLoad {
  15. // [super viewDidLoad];
  16. // // Do any additional setup after loading the view.
  17. // self.heightHeader = JX_SCREEN_TOP;
  18. // self.heightFooter = 0;
  19. // self.isGotoBack = YES;
  20. // self.isShowHeaderPull = NO;
  21. // self.isShowFooterPull = NO;
  22. //// self.title = Localized(@"JX_PublicNumber");
  23. // self.title = self.titleName;
  24. // [self createHeadAndFoot];
  25. // // WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  26. // // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width, self_height) configuration:config];
  27. // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP , self_width, self_height - JX_SCREEN_TOP)];
  28. //// [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://e-135639.chatnow.meiqia.com/dist/standalone.html"]]];
  29. // [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.link]]];
  30. // [self.view addSubview:self.wkWebView];
  31. //}
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. self.heightHeader = JX_SCREEN_TOP;
  36. self.heightFooter = 0;
  37. self.isGotoBack = NO;
  38. // self.title = Localized(@"JX_PublicNumber");
  39. // self.title = @"开奖";
  40. self.title = self.titleName;
  41. [self createHeadAndFoot];
  42. // WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  43. // self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width, self_height) configuration:config];
  44. self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP, self_width,self_height- JX_SCREEN_TOP - JX_SCREEN_BOTTOM_SAFE_AREA)];
  45. [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.link]]];
  46. // [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://qs77888.com"]]];
  47. self.wkWebView.UIDelegate = self;
  48. self.wkWebView.navigationDelegate = self;
  49. [self.view addSubview:self.wkWebView];
  50. [self setupUI];
  51. }
  52. - (void)setupUI {
  53. UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  54. label1.text = @"< 返回";
  55. UIBarButtonItem *lItem = [[UIBarButtonItem alloc] initWithCustomView:label1];
  56. [label1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftButtonClick)]];
  57. label1.userInteractionEnabled = YES;
  58. [self setLeftBarButtonItem:lItem];
  59. }
  60. - (void)leftButtonClick {
  61. [self dismissViewControllerAnimated:YES completion:nil];
  62. }
  63. // 根据WebView对于即将跳转的HTTP请求头信息和相关信息来决定是否跳转
  64. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  65. NSString * urlStr = navigationAction.request.URL.absoluteString;
  66. NSLog(@"发送跳转请求:%@",urlStr);
  67. //自己定义的协议头
  68. decisionHandler(WKNavigationActionPolicyAllow);
  69. }
  70. // 根据客户端受到的服务器响应头以及response相关信息来决定是否可以跳转
  71. - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
  72. NSString * urlStr = navigationResponse.response.URL.absoluteString;
  73. NSLog(@"当前跳转地址:%@",urlStr);
  74. //允许跳转
  75. decisionHandler(WKNavigationResponsePolicyAllow);
  76. //不允许跳转
  77. //decisionHandler(WKNavigationResponsePolicyCancel);
  78. }
  79. // 页面是弹出窗口 _blank 处理
  80. - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
  81. if (!navigationAction.targetFrame.isMainFrame) {
  82. [webView loadRequest:navigationAction.request];
  83. }
  84. return nil;
  85. }
  86. // 页面开始加载时调用
  87. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  88. [SVProgressHUD showWithStatus:@"正在加载中..."];
  89. }
  90. // 页面加载失败时调用
  91. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
  92. [SVProgressHUD dismiss];
  93. }
  94. // 当内容开始返回时调用
  95. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
  96. [SVProgressHUD dismiss];
  97. }
  98. // 页面加载完成之后调用
  99. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  100. [SVProgressHUD dismiss];
  101. }
  102. //提交发生错误时调用
  103. - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
  104. [SVProgressHUD dismiss];
  105. }
  106. // 接收到服务器跳转请求即服务重定向时之后调用
  107. - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
  108. [SVProgressHUD dismiss];
  109. }
  110. @end