123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // JXChatWebView.m
- // shiku_im
- //
- // Created by 123 on 2020/6/3.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXChatWebView.h"
- #import "CYWebAddPointVC.h"
- #import <WebKit/WebKit.h>
- #import "UIView+LK.h"
-
- @interface JXChatWebView ()<WKUIDelegate,WKNavigationDelegate,JXRoomObjectDelegate>
- @property (nonatomic,strong)WKWebView *wkWebView;
- @property (nonatomic,weak) NSString *linkName1;
- @property (nonatomic,weak) NSString *linkURL1;
- @property (nonatomic,weak) NSString *imgUrl1;
- @property (nonatomic,weak) NSString *linkName2;
- @property (nonatomic,weak) NSString *linkURL2;
- @property (nonatomic,weak) NSString *imgUrl2;
- @property (nonatomic,assign)int vcnum;
- @property (nonatomic,weak) UIView *titlesView;
- @property (nonatomic,weak) UIView *indicatorView;
- @property (nonatomic,weak) UIButton *button_n;
- @property (nonatomic,weak) UIButton *selectedButton;
- @end
- @implementation JXChatWebView
- #pragma mark 接受新消息广播
- - (UIStatusBarStyle)preferredStatusBarStyle{
-
- return UIStatusBarStyleDefault;
- }
- -(void)newMsgSend:(NSNotification *)notifacation
- {
- self.countTipL.hidden=NO;
- }
- -(void)newRequest:(NSNotification *)notifacation
- {
- self.countTipL.hidden=NO;
- }
- -(void)newMsgCome:(NSNotification *)notifacation
- {
- self.countTipL.hidden=NO;
- }
- - (id)init
- {
- self = [super init];
- if (self) {
- [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];//收到了一条新消息
- [g_notify addObserver:self selector:@selector(newMsgSend:) name:kXMPPMyLastSendNotifaction object:nil];//发送了一条消息
- [g_notify addObserver:self selector:@selector(newRequest:) name:kXMPPNewRequestNotifaction object:nil];//收到了一个好友验证类消息
-
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- // self.title = Localized(@"JX_PublicNumber");
- // self.title = @"开奖";
-
- if(AppStore == 1){
-
- } else {
- _vcnum = (int)g_App.linkArray.count;
- }
-
- if (self.vcnum < 0 || self.vcnum >2) {
- self.vcnum = 0;
- }else{
- for (int i = 0; i < self.vcnum; i++) {
- if (i == 0) {
- _linkName1 = g_App.linkArray[i][@"desc"];
- _linkURL1 = g_App.linkArray[i][@"link"];
- _imgUrl1 = g_App.linkArray[i][@"imgUrl"];
- if (_linkName1.length < 1) {
- _linkName1 = @"百度";
- }
- if (_linkURL1.length < 1) {
- _linkURL1 = @"http://www.baidu.com";
- }
- }else if (i == 1){
- _linkName2 = g_App.linkArray[i][@"desc"];
- _linkURL2 = g_App.linkArray[i][@"link"];
- _imgUrl2 = g_App.linkArray[i][@"imgUrl"];
- if (_linkName2.length < 1) {
- _linkName2 = @"百度";
- }
- if (_linkURL2.length < 1) {
- _linkURL2 = @"http://www.baidu.com";
- }
- }
- }
- }
-
- self.wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, self_width,self_height-JX_SCREEN_TOP)];
- self.wkWebView.backgroundColor=kRGBColor(250, 250, 250);
- [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkURL1]]];
- self.wkWebView.UIDelegate = self;
- self.wkWebView.navigationDelegate = self;
- [self.view addSubview:self.wkWebView];
-
-
-
- }
-
-
- - (void)rightButtonClick {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.wkWebView reload];
-
- });
- }
- - (void)leftButtonClick {
- [self.wkWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.strURL]]];
- }
- // 根据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];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:NO];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:NO];
- }
- @end
|