Commit a69d0eed7551c15c2ce9666dc36e886c0b03a259
1 parent
692aed9e
将CNWebView和CNWebViewController的webView统一为CNWebView
Showing
2 changed files
with
256 additions
and
204 deletions
metaCode/Classes/Main/HomePage/Controller/WebController/CNWebView.swift
| ... | ... | @@ -11,6 +11,10 @@ import WebViewJavascriptBridge |
| 11 | 11 | import CNLiveShareToolKit |
| 12 | 12 | import CommonCrypto |
| 13 | 13 | import CNLiveBusinessTools |
| 14 | +import SKPhotoBrowser | |
| 15 | + | |
| 16 | +//更新Web控制器导航回调 | |
| 17 | +typealias cnWebControllerUpdateNavBlock = (_ isFinish:Bool , _ titleName:String ,_ isDecidePolicy:Bool , _ urlStr:String)->Void | |
| 14 | 18 | |
| 15 | 19 | class CNWebView:UIView,WKNavigationDelegate{ |
| 16 | 20 | |
| ... | ... | @@ -21,11 +25,15 @@ class CNWebView:UIView,WKNavigationDelegate{ |
| 21 | 25 | return cnWebView |
| 22 | 26 | }() |
| 23 | 27 | |
| 24 | - | |
| 25 | 28 | var webUrl:URL?//初始URL |
| 26 | 29 | var currentUrl:String = ""//当前网页的url |
| 27 | 30 | var bridge:WKWebViewJavascriptBridge? |
| 28 | 31 | |
| 32 | + //CNWebController | |
| 33 | + var isCNWebController:Bool = false//是否网页控制器 | |
| 34 | + var webControllerUpdateNavBlock:cnWebControllerUpdateNavBlock? | |
| 35 | + | |
| 36 | + | |
| 29 | 37 | init(frame: CGRect, configuration: WKWebViewConfiguration ,url:URL?) { |
| 30 | 38 | super.init(frame: frame) |
| 31 | 39 | self.configuration = configuration |
| ... | ... | @@ -56,8 +64,9 @@ class CNWebView:UIView,WKNavigationDelegate{ |
| 56 | 64 | self.bridge = WKWebViewJavascriptBridge(for: self.cnWebView) |
| 57 | 65 | self.bridge?.setWebViewDelegate(self) |
| 58 | 66 | } |
| 59 | - //h5拉起原生分享 js call oc | |
| 67 | + //h5拉起原生 | |
| 60 | 68 | func configBridgeRegister() -> Void { |
| 69 | + //h5拉起原生分享 js call oc | |
| 61 | 70 | self.bridge?.registerHandler("wjjylzgVideoShare", handler: { data, responseCallback in |
| 62 | 71 | // print("js call oc\(data)") |
| 63 | 72 | let dic = data as! Dictionary<String, String> |
| ... | ... | @@ -70,6 +79,33 @@ class CNWebView:UIView,WKNavigationDelegate{ |
| 70 | 79 | } |
| 71 | 80 | |
| 72 | 81 | }) |
| 82 | + // 网页内容图片预览 | |
| 83 | + self.bridge?.registerHandler("wjjPreviewImage", handler: { data, responseCallback in | |
| 84 | + // print("js call oc\(data)") | |
| 85 | + var images = [SKPhoto]() | |
| 86 | + let dic = data as! Dictionary<String, Any> | |
| 87 | + let index = (dic["index"] as! NSString).integerValue | |
| 88 | + let imageArray = dic["imgArr"] as! NSArray | |
| 89 | + var imgArray = NSMutableArray() | |
| 90 | + for dict in imageArray { | |
| 91 | + var imgUrl = "" | |
| 92 | + if let dictemp = dict as? String{ | |
| 93 | + imgArray.add(dictemp) | |
| 94 | + imgUrl = dictemp | |
| 95 | + }else if let dictemp = dict as? Dictionary<String, Any>{ | |
| 96 | + imgArray.add(dictemp["src"] ?? "") | |
| 97 | + imgUrl = dictemp["src"] as! String | |
| 98 | + } | |
| 99 | + let photo = SKPhoto.photoWithImageURL(imgUrl) | |
| 100 | + photo.shouldCachePhotoURLImage = false | |
| 101 | + photo.photoURL = imgUrl | |
| 102 | + images.append(photo) | |
| 103 | + } | |
| 104 | + let browser = SKPhotoBrowser(photos: images) | |
| 105 | + browser.initializePageIndex(index) | |
| 106 | + currentViewController()?.present(browser, animated: true) | |
| 107 | + | |
| 108 | + }) | |
| 73 | 109 | } |
| 74 | 110 | |
| 75 | 111 | required init?(coder: NSCoder) { |
| ... | ... | @@ -143,7 +179,9 @@ class CNWebView:UIView,WKNavigationDelegate{ |
| 143 | 179 | // 页面加载完成之后调用 |
| 144 | 180 | func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { |
| 145 | 181 | print("didFinish") |
| 146 | -// titleName = webView.title! | |
| 182 | +// if (self.webControllerUpdateNavBlock?(true, "", false, "") != nil){ | |
| 183 | + self.webControllerUpdateNavBlock?(true, webView.title!, false , "") | |
| 184 | +// } | |
| 147 | 185 | } |
| 148 | 186 | // 页面加载失败时调用 |
| 149 | 187 | func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { |
| ... | ... | @@ -170,7 +208,9 @@ class CNWebView:UIView,WKNavigationDelegate{ |
| 170 | 208 | var urlStr = (navigationAction.request.url?.absoluteString)! |
| 171 | 209 | |
| 172 | 210 | if navigationAction.request.url?.host == WjjH5 { |
| 173 | - | |
| 211 | +// if (self.webControllerUpdateNavBlock?(false, "", true, "") != nil){ | |
| 212 | + self.webControllerUpdateNavBlock?(false, "", true , urlStr) | |
| 213 | +// } | |
| 174 | 214 | // if urlStr.contains("&isWjjReport=true") || urlStr.contains("?isWjjReport=true"){ |
| 175 | 215 | // self.rightNavBtns = [self.moreNavBtn] |
| 176 | 216 | // self.moreNavBtn.isHidden = false | ... | ... |
metaCode/Classes/Main/HomePage/Controller/WebController/CNWebViewController.swift
| ... | ... | @@ -22,7 +22,7 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 22 | 22 | var bridge:WKWebViewJavascriptBridge? |
| 23 | 23 | var currentUrl:String = ""//当前网页的url |
| 24 | 24 | |
| 25 | - lazy var webView: WKWebView = { | |
| 25 | + lazy var webView: CNWebView = { | |
| 26 | 26 | let configuration = WKWebViewConfiguration() |
| 27 | 27 | configuration.allowsInlineMediaPlayback = true |
| 28 | 28 | let preferences = WKPreferences() |
| ... | ... | @@ -31,11 +31,11 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 31 | 31 | configuration.preferences.minimumFontSize = 0.0 |
| 32 | 32 | configuration.preferences = preferences |
| 33 | 33 | configuration.userContentController = WKUserContentController() |
| 34 | - | |
| 35 | - let webView = WKWebView(frame: CGRectMake(0, 0, Width, Height), configuration: configuration) | |
| 36 | - webView.scrollView.showsVerticalScrollIndicator = false | |
| 37 | - webView.scrollView.showsHorizontalScrollIndicator = false | |
| 38 | -// webView.navigationDelegate = self | |
| 34 | + let webView = CNWebView(frame: CGRectMake(0, 0, Width, Height), configuration: configuration, url: _url) | |
| 35 | +// let webView = WKWebView(frame: CGRectMake(0, 0, Width, Height), configuration: configuration) | |
| 36 | + webView.cnWebView.scrollView.showsVerticalScrollIndicator = false | |
| 37 | + webView.cnWebView.scrollView.showsHorizontalScrollIndicator = false | |
| 38 | + webView.isCNWebController = true | |
| 39 | 39 | return webView |
| 40 | 40 | }() |
| 41 | 41 | |
| ... | ... | @@ -63,83 +63,95 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 63 | 63 | super.viewDidLoad() |
| 64 | 64 | navigationBarHidden = false |
| 65 | 65 | self.view.addSubview(self.webView) |
| 66 | + self.webView.webControllerUpdateNavBlock = { isFinish , title,isDecidePolicy ,urlStr in | |
| 67 | + if isFinish{ | |
| 68 | + self.titleName = title | |
| 69 | + }else if isDecidePolicy{ | |
| 70 | + if urlStr.contains("&isWjjReport=true") || urlStr.contains("?isWjjReport=true"){ | |
| 71 | + self.rightNavBtns = [self.moreNavBtn] | |
| 72 | + self.moreNavBtn.isHidden = false | |
| 73 | + }else{ | |
| 74 | + self.moreNavBtn.isHidden = true | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 66 | 78 | webView.snp.makeConstraints { make in |
| 67 | 79 | make.top.equalTo(get_system_nav_height()) |
| 68 | 80 | make.left.right.bottom.equalToSuperview() |
| 69 | 81 | } |
| 70 | - webView.evaluateJavaScript("navigator.userAgent") { [self] result, error in | |
| 71 | - let userAgent = result as! String | |
| 72 | - if error == nil && userAgent.count > 0 { | |
| 73 | - if !userAgent.contains(CNLiveMCEnvironmentManager.shared.base_web_UA) { | |
| 74 | - let newUserAgent = userAgent + CNLiveMCEnvironmentManager.shared.base_web_UA | |
| 75 | - webView.customUserAgent = newUserAgent | |
| 76 | - | |
| 77 | - if (_url != nil){ | |
| 78 | - let urlStr = self.checkURLWithStr(urlStr: _url!.absoluteString) | |
| 79 | - self.currentUrl = urlStr | |
| 80 | - | |
| 81 | - webView.load(URLRequest.init(url:URL(string: urlStr)!)) | |
| 82 | - } | |
| 83 | - self.configBridge() | |
| 84 | - self.configBridgeRegister() | |
| 85 | - } | |
| 86 | - } | |
| 87 | - } | |
| 88 | - } | |
| 89 | - | |
| 90 | - func configBridge(){ | |
| 91 | - WKWebViewJavascriptBridge.enableLogging() | |
| 92 | - self.bridge = WKWebViewJavascriptBridge(for: self.webView) | |
| 93 | - self.bridge?.setWebViewDelegate(self) | |
| 82 | +// webView.cnWebView.evaluateJavaScript("navigator.userAgent") { [self] result, error in | |
| 83 | +// let userAgent = result as! String | |
| 84 | +// if error == nil && userAgent.count > 0 { | |
| 85 | +// if !userAgent.contains(CNLiveMCEnvironmentManager.shared.base_web_UA) { | |
| 86 | +// let newUserAgent = userAgent + CNLiveMCEnvironmentManager.shared.base_web_UA | |
| 87 | +// webView.cnWebView.customUserAgent = newUserAgent | |
| 88 | +// | |
| 89 | +// if (_url != nil){ | |
| 90 | +// let urlStr = self.checkURLWithStr(urlStr: _url!.absoluteString) | |
| 91 | +// self.currentUrl = urlStr | |
| 92 | +// | |
| 93 | +// webView.cnWebView.load(URLRequest.init(url:URL(string: urlStr)!)) | |
| 94 | +// } | |
| 95 | +// self.configBridge() | |
| 96 | +// self.configBridgeRegister() | |
| 97 | +// } | |
| 98 | +// } | |
| 99 | +// } | |
| 94 | 100 | } |
| 95 | - | |
| 96 | - func configBridgeRegister() -> Void { | |
| 97 | - //h5拉起原生分享 js call oc | |
| 98 | - self.bridge?.registerHandler("wjjylzgVideoShare", handler: { data, responseCallback in | |
| 99 | -// print("js call oc\(data)") | |
| 100 | - let dic = data as! Dictionary<String, String> | |
| 101 | - CNLiveShareManager.showShareViewWithParam(forShareTitle: dic["title"], shareUrl: dic["shareUrl"], shareDesc: dic["subTitle"], shareImage: dic["cover"], screenFull: false, hiddenWjj: true, hiddenQQ: false, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: self, topImage: [], topTitles: [], platformType: .all) { title in | |
| 102 | - | |
| 103 | - } completerBlock: { resultType, platformType, typeString in | |
| 104 | - if resultType == .succ{ | |
| 105 | - | |
| 106 | - } | |
| 107 | - } | |
| 108 | 101 | |
| 109 | - }) | |
| 110 | - | |
| 111 | - // 网页内容图片预览 | |
| 112 | - self.bridge?.registerHandler("wjjPreviewImage", handler: { data, responseCallback in | |
| 113 | - // print("js call oc\(data)") | |
| 114 | - var images = [SKPhoto]() | |
| 115 | - let dic = data as! Dictionary<String, Any> | |
| 116 | - let index = (dic["index"] as! NSString).integerValue | |
| 117 | - let imageArray = dic["imgArr"] as! NSArray | |
| 118 | - var imgArray = NSMutableArray() | |
| 119 | - for dict in imageArray { | |
| 120 | - var imgUrl = "" | |
| 121 | - if let dictemp = dict as? String{ | |
| 122 | - imgArray.add(dictemp) | |
| 123 | - imgUrl = dictemp | |
| 124 | - }else if let dictemp = dict as? Dictionary<String, Any>{ | |
| 125 | - imgArray.add(dictemp["src"] ?? "") | |
| 126 | - imgUrl = dictemp["src"] as! String | |
| 127 | - } | |
| 128 | - let photo = SKPhoto.photoWithImageURL(imgUrl) | |
| 129 | - photo.shouldCachePhotoURLImage = false | |
| 130 | - photo.photoURL = imgUrl | |
| 131 | - images.append(photo) | |
| 132 | - } | |
| 133 | - let browser = SKPhotoBrowser(photos: images) | |
| 134 | - browser.initializePageIndex(index) | |
| 135 | - currentViewController()?.present(browser, animated: true) | |
| 136 | - | |
| 137 | - }) | |
| 138 | - } | |
| 102 | +// func configBridge(){ | |
| 103 | +// WKWebViewJavascriptBridge.enableLogging() | |
| 104 | +// self.bridge = WKWebViewJavascriptBridge(for: self.webView.cnWebView) | |
| 105 | +// self.bridge?.setWebViewDelegate(self) | |
| 106 | +// } | |
| 107 | +// | |
| 108 | +// func configBridgeRegister() -> Void { | |
| 109 | +// //h5拉起原生分享 js call oc | |
| 110 | +// self.bridge?.registerHandler("wjjylzgVideoShare", handler: { data, responseCallback in | |
| 111 | +//// print("js call oc\(data)") | |
| 112 | +// let dic = data as! Dictionary<String, String> | |
| 113 | +// CNLiveShareManager.showShareViewWithParam(forShareTitle: dic["title"], shareUrl: dic["shareUrl"], shareDesc: dic["subTitle"], shareImage: dic["cover"], screenFull: false, hiddenWjj: true, hiddenQQ: false, hiddenWB: true, hiddenLifeCircle: true, hiddenWechatCircle: false, hiddenWechat: false, hiddenSafari: true, formVC: self, topImage: [], topTitles: [], platformType: .all) { title in | |
| 114 | +// | |
| 115 | +// } completerBlock: { resultType, platformType, typeString in | |
| 116 | +// if resultType == .succ{ | |
| 117 | +// | |
| 118 | +// } | |
| 119 | +// } | |
| 120 | +// | |
| 121 | +// }) | |
| 122 | +// | |
| 123 | +// // 网页内容图片预览 | |
| 124 | +// self.bridge?.registerHandler("wjjPreviewImage", handler: { data, responseCallback in | |
| 125 | +// // print("js call oc\(data)") | |
| 126 | +// var images = [SKPhoto]() | |
| 127 | +// let dic = data as! Dictionary<String, Any> | |
| 128 | +// let index = (dic["index"] as! NSString).integerValue | |
| 129 | +// let imageArray = dic["imgArr"] as! NSArray | |
| 130 | +// var imgArray = NSMutableArray() | |
| 131 | +// for dict in imageArray { | |
| 132 | +// var imgUrl = "" | |
| 133 | +// if let dictemp = dict as? String{ | |
| 134 | +// imgArray.add(dictemp) | |
| 135 | +// imgUrl = dictemp | |
| 136 | +// }else if let dictemp = dict as? Dictionary<String, Any>{ | |
| 137 | +// imgArray.add(dictemp["src"] ?? "") | |
| 138 | +// imgUrl = dictemp["src"] as! String | |
| 139 | +// } | |
| 140 | +// let photo = SKPhoto.photoWithImageURL(imgUrl) | |
| 141 | +// photo.shouldCachePhotoURLImage = false | |
| 142 | +// photo.photoURL = imgUrl | |
| 143 | +// images.append(photo) | |
| 144 | +// } | |
| 145 | +// let browser = SKPhotoBrowser(photos: images) | |
| 146 | +// browser.initializePageIndex(index) | |
| 147 | +// currentViewController()?.present(browser, animated: true) | |
| 148 | +// | |
| 149 | +// }) | |
| 150 | +// } | |
| 139 | 151 | |
| 140 | 152 | //点击...分享获取h5参数oc call js |
| 141 | 153 | func configBridgeCallHander() -> Void { |
| 142 | - self.bridge?.callHandler("wjjClientGetShareParaFromJS", data: ["":""], responseCallback: { data in | |
| 154 | + self.webView.bridge?.callHandler("wjjClientGetShareParaFromJS", data: ["":""], responseCallback: { data in | |
| 143 | 155 | // print("js call oc\(data)") |
| 144 | 156 | let dic = data as! Dictionary<String, String> |
| 145 | 157 | // let shareType = dic["shareType"] |
| ... | ... | @@ -169,59 +181,59 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 169 | 181 | }) |
| 170 | 182 | } |
| 171 | 183 | |
| 172 | - func checkURLWithStr(urlStr:String) -> String{ | |
| 173 | - if URL(string: urlStr)?.host != WjjH5 { | |
| 174 | - return urlStr//不是wjjh5不作处理 | |
| 175 | - } | |
| 176 | - var str = urlStr | |
| 177 | - let date = Date() | |
| 178 | - let formatter = DateFormatter() | |
| 179 | - formatter.dateFormat = "yyyyMMdd" | |
| 180 | - let dateStr = formatter.string(from: date) | |
| 181 | - let sidStr = String(format: "%@%@", UserInfoManager.shared.userInfo.uid,dateStr) | |
| 182 | - let signStr = sidStr.crypt(operation: CCOperation(kCCEncrypt), key: CNLiveMCEnvironmentManager.shared.appKey) | |
| 183 | - //看是 appKey还是appKeywjj | |
| 184 | - let sidSignStr = (signStr ?? "").isEmpty ? "" : signStr | |
| 185 | - let sourceArray = str.components(separatedBy: "?") | |
| 186 | - let buildVersion = Bundle.main.infoDictionary!["CFBundleVersion"] as! String | |
| 187 | - let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String | |
| 188 | - let uuid = CNLiveBusinessTools.getUidForStat(Date()) | |
| 189 | - if sourceArray.count == 1{ | |
| 190 | - //是wjjh5且无参数 | |
| 191 | - str = String(format: "%@?shareSid=%@&sid=%@&plat=i&ver=%@&version=%@&wjjFrom=apple&wjjUUID=%@&appId=%@&voteId=%@&wjjToken=%@", str,UserInfoManager.shared.userInfo.uid,UserInfoManager.shared.userInfo.uid,buildVersion,appVersion,uuid,CNLiveMCEnvironmentManager.shared.appId,sidSignStr!,UserInfoManager.shared.userInfo.token) | |
| 192 | - return str | |
| 193 | - } | |
| 194 | - //是wjjh5且有参数 | |
| 195 | - let paraArr = NSMutableArray(array: ["shareSid=","sid=","plat=","ver=","version=","wjjFrom=","wjjUUID=","appId=","voteId=","wjjToken="]) | |
| 196 | - let valueArr = NSMutableArray(array:[UserInfoManager.shared.userInfo.uid,UserInfoManager.shared.userInfo.uid,"i",buildVersion,appVersion,"apple",uuid,CNLiveMCEnvironmentManager.shared.appId,sidSignStr!,UserInfoManager.shared.userInfo.token]) | |
| 197 | - var i = 0 | |
| 198 | - for paraStr in paraArr{ | |
| 199 | - let tempStr = paraStr as! String | |
| 200 | - let paramStr = "&".appending(tempStr) | |
| 201 | - let paramStr2 = "?".appending(tempStr) | |
| 202 | - | |
| 203 | - if str.contains(paramStr){ | |
| 204 | - //包含则替换 &sid= | |
| 205 | - let lastStr = str.components(separatedBy: tempStr).last | |
| 206 | - let lastSeparatedStr = (lastStr?.components(separatedBy: "&").first)! | |
| 207 | - let oldStr = tempStr.appending(lastSeparatedStr) | |
| 208 | - let tempValueStr = tempStr.appending(valueArr[i] as! String) | |
| 209 | - str = str.replacingOccurrences(of: oldStr, with: tempValueStr) | |
| 210 | - }else if str.contains(paramStr2){ | |
| 211 | - //包含则替换 &sid= | |
| 212 | - let lastStr = str.components(separatedBy: tempStr).last | |
| 213 | - let lastSeparatedStr = (lastStr?.components(separatedBy: "&").first)! | |
| 214 | - let oldStr = tempStr.appending(lastSeparatedStr) | |
| 215 | - let tempValueStr = tempStr.appending(valueArr[i] as! String) | |
| 216 | - str = str.replacingOccurrences(of: oldStr, with: tempValueStr) | |
| 217 | - }else{ | |
| 218 | - //不包含则拼接 | |
| 219 | - str = String(format: "%@&%@%@", str,tempStr,valueArr[i] as! String) | |
| 220 | - } | |
| 221 | - i = i + 1 | |
| 222 | - } | |
| 223 | - return str | |
| 224 | - } | |
| 184 | +// func checkURLWithStr(urlStr:String) -> String{ | |
| 185 | +// if URL(string: urlStr)?.host != WjjH5 { | |
| 186 | +// return urlStr//不是wjjh5不作处理 | |
| 187 | +// } | |
| 188 | +// var str = urlStr | |
| 189 | +// let date = Date() | |
| 190 | +// let formatter = DateFormatter() | |
| 191 | +// formatter.dateFormat = "yyyyMMdd" | |
| 192 | +// let dateStr = formatter.string(from: date) | |
| 193 | +// let sidStr = String(format: "%@%@", UserInfoManager.shared.userInfo.uid,dateStr) | |
| 194 | +// let signStr = sidStr.crypt(operation: CCOperation(kCCEncrypt), key: CNLiveMCEnvironmentManager.shared.appKey) | |
| 195 | +// //看是 appKey还是appKeywjj | |
| 196 | +// let sidSignStr = (signStr ?? "").isEmpty ? "" : signStr | |
| 197 | +// let sourceArray = str.components(separatedBy: "?") | |
| 198 | +// let buildVersion = Bundle.main.infoDictionary!["CFBundleVersion"] as! String | |
| 199 | +// let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String | |
| 200 | +// let uuid = CNLiveBusinessTools.getUidForStat(Date()) | |
| 201 | +// if sourceArray.count == 1{ | |
| 202 | +// //是wjjh5且无参数 | |
| 203 | +// str = String(format: "%@?shareSid=%@&sid=%@&plat=i&ver=%@&version=%@&wjjFrom=apple&wjjUUID=%@&appId=%@&voteId=%@&wjjToken=%@", str,UserInfoManager.shared.userInfo.uid,UserInfoManager.shared.userInfo.uid,buildVersion,appVersion,uuid,CNLiveMCEnvironmentManager.shared.appId,sidSignStr!,UserInfoManager.shared.userInfo.token) | |
| 204 | +// return str | |
| 205 | +// } | |
| 206 | +// //是wjjh5且有参数 | |
| 207 | +// let paraArr = NSMutableArray(array: ["shareSid=","sid=","plat=","ver=","version=","wjjFrom=","wjjUUID=","appId=","voteId=","wjjToken="]) | |
| 208 | +// let valueArr = NSMutableArray(array:[UserInfoManager.shared.userInfo.uid,UserInfoManager.shared.userInfo.uid,"i",buildVersion,appVersion,"apple",uuid,CNLiveMCEnvironmentManager.shared.appId,sidSignStr!,UserInfoManager.shared.userInfo.token]) | |
| 209 | +// var i = 0 | |
| 210 | +// for paraStr in paraArr{ | |
| 211 | +// let tempStr = paraStr as! String | |
| 212 | +// let paramStr = "&".appending(tempStr) | |
| 213 | +// let paramStr2 = "?".appending(tempStr) | |
| 214 | +// | |
| 215 | +// if str.contains(paramStr){ | |
| 216 | +// //包含则替换 &sid= | |
| 217 | +// let lastStr = str.components(separatedBy: tempStr).last | |
| 218 | +// let lastSeparatedStr = (lastStr?.components(separatedBy: "&").first)! | |
| 219 | +// let oldStr = tempStr.appending(lastSeparatedStr) | |
| 220 | +// let tempValueStr = tempStr.appending(valueArr[i] as! String) | |
| 221 | +// str = str.replacingOccurrences(of: oldStr, with: tempValueStr) | |
| 222 | +// }else if str.contains(paramStr2){ | |
| 223 | +// //包含则替换 &sid= | |
| 224 | +// let lastStr = str.components(separatedBy: tempStr).last | |
| 225 | +// let lastSeparatedStr = (lastStr?.components(separatedBy: "&").first)! | |
| 226 | +// let oldStr = tempStr.appending(lastSeparatedStr) | |
| 227 | +// let tempValueStr = tempStr.appending(valueArr[i] as! String) | |
| 228 | +// str = str.replacingOccurrences(of: oldStr, with: tempValueStr) | |
| 229 | +// }else{ | |
| 230 | +// //不包含则拼接 | |
| 231 | +// str = String(format: "%@&%@%@", str,tempStr,valueArr[i] as! String) | |
| 232 | +// } | |
| 233 | +// i = i + 1 | |
| 234 | +// } | |
| 235 | +// return str | |
| 236 | +// } | |
| 225 | 237 | |
| 226 | 238 | // MARK: - BtnAction |
| 227 | 239 | // 内部链接右上角···分享 |
| ... | ... | @@ -229,83 +241,83 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 229 | 241 | self.configBridgeCallHander() |
| 230 | 242 | } |
| 231 | 243 | override func ClickBackBtn() { |
| 232 | - if self.webView.canGoBack{ | |
| 233 | - self.webView.goBack() | |
| 244 | + if self.webView.cnWebView.canGoBack{ | |
| 245 | + self.webView.cnWebView.goBack() | |
| 234 | 246 | }else{ |
| 235 | 247 | super.ClickBackBtn() |
| 236 | 248 | } |
| 237 | 249 | } |
| 238 | 250 | |
| 239 | 251 | // MARK: - WKWebViewDelegate |
| 240 | - // 页面开始加载时调用 | |
| 241 | - func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { | |
| 242 | -// print("didStartProvisionalNavigation") | |
| 243 | - } | |
| 244 | - // 当内容开始返回时调用 | |
| 245 | - func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { | |
| 246 | -// print("didCommit") | |
| 247 | - } | |
| 248 | - | |
| 249 | - // 页面加载完成之后调用 | |
| 250 | - func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
| 251 | -// print("didFinish") | |
| 252 | - titleName = webView.title! | |
| 253 | - } | |
| 254 | - // 页面加载失败时调用 | |
| 255 | - func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { | |
| 256 | -// print("didFailProvisionalNavigation") | |
| 257 | - } | |
| 258 | - // 接收到服务器跳转请求之后调用 | |
| 259 | - func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) { | |
| 260 | -// print("didReceiveServerRedirectForProvisionalNavigation") | |
| 261 | - } | |
| 262 | - // 在收到响应后,决定是否跳转 -> 默认允许 | |
| 263 | - func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { | |
| 264 | - | |
| 265 | -// print("decidePolicyFornavigationResponse") | |
| 266 | - | |
| 267 | - //允许跳转 | |
| 268 | - decisionHandler(.allow) | |
| 269 | - //不允许跳转 | |
| 270 | - // decisionHandler(.cancel) | |
| 271 | - } | |
| 272 | - // 在发送请求之前,决定是否跳转 -> 默认允许 | |
| 273 | - func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | |
| 274 | -// print("decidePolicyFornavigationAction") | |
| 275 | - | |
| 276 | - var urlStr = (navigationAction.request.url?.absoluteString)! | |
| 277 | - | |
| 278 | - if navigationAction.request.url?.host == WjjH5 { | |
| 279 | - | |
| 280 | - if urlStr.contains("&isWjjReport=true") || urlStr.contains("?isWjjReport=true"){ | |
| 281 | - self.rightNavBtns = [self.moreNavBtn] | |
| 282 | - self.moreNavBtn.isHidden = false | |
| 283 | - }else{ | |
| 284 | - self.moreNavBtn.isHidden = true | |
| 285 | - } | |
| 286 | - | |
| 287 | - urlStr = self.checkURLWithStr(urlStr: urlStr) | |
| 288 | - self.currentUrl = urlStr | |
| 289 | - } | |
| 290 | - | |
| 291 | - if navigationAction.navigationType == .other{ | |
| 292 | - //跳转Appstore | |
| 293 | - let url = URL(string: "https://apps.apple.com/cn/app/%E7%BD%91%E5%AE%B6%E5%AE%B6%E5%95%86%E5%AE%B6%E7%89%88/id1337575497") | |
| 294 | - if url == navigationAction.request.url { | |
| 295 | - if UIApplication.shared.canOpenURL(url!) { UIApplication.shared.open(url!, options: [:], completionHandler: nil) | |
| 296 | - } | |
| 297 | - } | |
| 298 | - }else if navigationAction.navigationType == .linkActivated{ | |
| 299 | - | |
| 300 | - //以后可判断h5地址 ,可跳转原生页面或网页 | |
| 301 | - //暂时只跳h5 | |
| 302 | - let webVC = CNWebViewController() | |
| 303 | - webVC.url = URL(string: urlStr) | |
| 304 | - navigationViewController().pushViewController(webVC, animated: pushAnimated) | |
| 305 | - decisionHandler(.cancel) | |
| 306 | - return | |
| 307 | - | |
| 308 | - } | |
| 309 | - decisionHandler(.allow) | |
| 310 | - } | |
| 252 | +// // 页面开始加载时调用 | |
| 253 | +// func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { | |
| 254 | +//// print("didStartProvisionalNavigation") | |
| 255 | +// } | |
| 256 | +// // 当内容开始返回时调用 | |
| 257 | +// func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { | |
| 258 | +//// print("didCommit") | |
| 259 | +// } | |
| 260 | +// | |
| 261 | +// // 页面加载完成之后调用 | |
| 262 | +// func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
| 263 | +//// print("didFinish") | |
| 264 | +// titleName = webView.title! | |
| 265 | +// } | |
| 266 | +// // 页面加载失败时调用 | |
| 267 | +// func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { | |
| 268 | +//// print("didFailProvisionalNavigation") | |
| 269 | +// } | |
| 270 | +// // 接收到服务器跳转请求之后调用 | |
| 271 | +// func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) { | |
| 272 | +//// print("didReceiveServerRedirectForProvisionalNavigation") | |
| 273 | +// } | |
| 274 | +// // 在收到响应后,决定是否跳转 -> 默认允许 | |
| 275 | +// func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) { | |
| 276 | +// | |
| 277 | +//// print("decidePolicyFornavigationResponse") | |
| 278 | +// | |
| 279 | +// //允许跳转 | |
| 280 | +// decisionHandler(.allow) | |
| 281 | +// //不允许跳转 | |
| 282 | +// // decisionHandler(.cancel) | |
| 283 | +// } | |
| 284 | +// // 在发送请求之前,决定是否跳转 -> 默认允许 | |
| 285 | +// func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | |
| 286 | +//// print("decidePolicyFornavigationAction") | |
| 287 | +// | |
| 288 | +// var urlStr = (navigationAction.request.url?.absoluteString)! | |
| 289 | +// | |
| 290 | +// if navigationAction.request.url?.host == WjjH5 { | |
| 291 | +// | |
| 292 | +// if urlStr.contains("&isWjjReport=true") || urlStr.contains("?isWjjReport=true"){ | |
| 293 | +// self.rightNavBtns = [self.moreNavBtn] | |
| 294 | +// self.moreNavBtn.isHidden = false | |
| 295 | +// }else{ | |
| 296 | +// self.moreNavBtn.isHidden = true | |
| 297 | +// } | |
| 298 | +// | |
| 299 | +// urlStr = self.checkURLWithStr(urlStr: urlStr) | |
| 300 | +// self.currentUrl = urlStr | |
| 301 | +// } | |
| 302 | +// | |
| 303 | +// if navigationAction.navigationType == .other{ | |
| 304 | +// //跳转Appstore | |
| 305 | +// let url = URL(string: "https://apps.apple.com/cn/app/%E7%BD%91%E5%AE%B6%E5%AE%B6%E5%95%86%E5%AE%B6%E7%89%88/id1337575497") | |
| 306 | +// if url == navigationAction.request.url { | |
| 307 | +// if UIApplication.shared.canOpenURL(url!) { UIApplication.shared.open(url!, options: [:], completionHandler: nil) | |
| 308 | +// } | |
| 309 | +// } | |
| 310 | +// }else if navigationAction.navigationType == .linkActivated{ | |
| 311 | +// | |
| 312 | +// //以后可判断h5地址 ,可跳转原生页面或网页 | |
| 313 | +// //暂时只跳h5 | |
| 314 | +// let webVC = CNWebViewController() | |
| 315 | +// webVC.url = URL(string: urlStr) | |
| 316 | +// navigationViewController().pushViewController(webVC, animated: pushAnimated) | |
| 317 | +// decisionHandler(.cancel) | |
| 318 | +// return | |
| 319 | +// | |
| 320 | +// } | |
| 321 | +// decisionHandler(.allow) | |
| 322 | +// } | |
| 311 | 323 | } | ... | ... |