Commit 692aed9edcd8815e9ca989bc87e04ef84cf9e9aa
1 parent
821d2c98
网页内容图片预览
Showing
1 changed file
with
31 additions
and
1 deletions
metaCode/Classes/Main/HomePage/Controller/WebController/CNWebViewController.swift
| ... | ... | @@ -11,6 +11,7 @@ import WebViewJavascriptBridge |
| 11 | 11 | import CNLiveShareToolKit |
| 12 | 12 | import CommonCrypto |
| 13 | 13 | import CNLiveBusinessTools |
| 14 | +import SKPhotoBrowser | |
| 14 | 15 | |
| 15 | 16 | |
| 16 | 17 | let WjjH5 = "wjjh5.cnlive.com" |
| ... | ... | @@ -91,8 +92,9 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 91 | 92 | self.bridge = WKWebViewJavascriptBridge(for: self.webView) |
| 92 | 93 | self.bridge?.setWebViewDelegate(self) |
| 93 | 94 | } |
| 94 | - //h5拉起原生分享 js call oc | |
| 95 | + | |
| 95 | 96 | func configBridgeRegister() -> Void { |
| 97 | + //h5拉起原生分享 js call oc | |
| 96 | 98 | self.bridge?.registerHandler("wjjylzgVideoShare", handler: { data, responseCallback in |
| 97 | 99 | // print("js call oc\(data)") |
| 98 | 100 | let dic = data as! Dictionary<String, String> |
| ... | ... | @@ -105,6 +107,34 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ |
| 105 | 107 | } |
| 106 | 108 | |
| 107 | 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 | + }) | |
| 108 | 138 | } |
| 109 | 139 | |
| 110 | 140 | //点击...分享获取h5参数oc call js | ... | ... |