Commit 2f8f0c49 authored by David黄金龙's avatar David黄金龙

与H5 交互的 webView

parent 1f3b3045
......@@ -504,7 +504,7 @@
A592FE952BA6D23C0062FACA /* YHCertificateEntryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A592FE942BA6D23C0062FACA /* YHCertificateEntryCell.swift */; };
A592FE972BA6DB340062FACA /* YHCertificateViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A592FE962BA6DB340062FACA /* YHCertificateViewModel.swift */; };
A59B43C72C48F68200B28379 /* YHEvaluationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43C62C48F68200B28379 /* YHEvaluationView.swift */; };
A59B43C92C491FB100B28379 /* YHEvaluationViewVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43C82C491FB100B28379 /* YHEvaluationViewVC.swift */; };
A59B43C92C491FB100B28379 /* YHH5WebViewVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43C82C491FB100B28379 /* YHH5WebViewVC.swift */; };
A59B43CB2C4A151200B28379 /* YHStatusAdvantageVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43CA2C4A151200B28379 /* YHStatusAdvantageVC.swift */; };
A59B43CD2C4A36DF00B28379 /* YHStatusAdvantageBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43CC2C4A36DF00B28379 /* YHStatusAdvantageBottomView.swift */; };
A59B43CF2C4B5AD100B28379 /* YHShareViewOnTablebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59B43CE2C4B5AD100B28379 /* YHShareViewOnTablebarView.swift */; };
......@@ -578,6 +578,7 @@
A5EF21372BA6E2D1005027E6 /* YHQuestionAndAnswerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EF21362BA6E2D1005027E6 /* YHQuestionAndAnswerModel.swift */; };
A5EF213B2BA6EC98005027E6 /* YHQuestionAndAnswerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5EF213A2BA6EC98005027E6 /* YHQuestionAndAnswerCell.swift */; };
A5F8AC082B9F414000A21EFA /* YHCustomTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F8AC072B9F414000A21EFA /* YHCustomTextView.swift */; };
A5FD45232C523DD300908AD9 /* YHJsApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FD45222C523DD300908AD9 /* YHJsApi.swift */; };
A5FD63BD2B623C2C00D1D9DA /* YHInformationPerfectListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FD63BC2B623C2C00D1D9DA /* YHInformationPerfectListVC.swift */; };
A5FD63BF2B6250BC00D1D9DA /* YHInformationPerfectCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FD63BE2B6250BC00D1D9DA /* YHInformationPerfectCell.swift */; };
A5FD63C12B62616D00D1D9DA /* YHInformationPerfectModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FD63C02B62616D00D1D9DA /* YHInformationPerfectModel.swift */; };
......@@ -1130,7 +1131,7 @@
A592FE942BA6D23C0062FACA /* YHCertificateEntryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateEntryCell.swift; sourceTree = "<group>"; };
A592FE962BA6DB340062FACA /* YHCertificateViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YHCertificateViewModel.swift; sourceTree = "<group>"; };
A59B43C62C48F68200B28379 /* YHEvaluationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHEvaluationView.swift; sourceTree = "<group>"; };
A59B43C82C491FB100B28379 /* YHEvaluationViewVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHEvaluationViewVC.swift; sourceTree = "<group>"; };
A59B43C82C491FB100B28379 /* YHH5WebViewVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHH5WebViewVC.swift; sourceTree = "<group>"; };
A59B43CA2C4A151200B28379 /* YHStatusAdvantageVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHStatusAdvantageVC.swift; sourceTree = "<group>"; };
A59B43CC2C4A36DF00B28379 /* YHStatusAdvantageBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHStatusAdvantageBottomView.swift; sourceTree = "<group>"; };
A59B43CE2C4B5AD100B28379 /* YHShareViewOnTablebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareViewOnTablebarView.swift; sourceTree = "<group>"; };
......@@ -1205,6 +1206,7 @@
A5EF21362BA6E2D1005027E6 /* YHQuestionAndAnswerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHQuestionAndAnswerModel.swift; sourceTree = "<group>"; };
A5EF213A2BA6EC98005027E6 /* YHQuestionAndAnswerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHQuestionAndAnswerCell.swift; sourceTree = "<group>"; };
A5F8AC072B9F414000A21EFA /* YHCustomTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YHCustomTextView.swift; sourceTree = "<group>"; };
A5FD45222C523DD300908AD9 /* YHJsApi.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YHJsApi.swift; sourceTree = "<group>"; };
A5FD63BC2B623C2C00D1D9DA /* YHInformationPerfectListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInformationPerfectListVC.swift; sourceTree = "<group>"; };
A5FD63BE2B6250BC00D1D9DA /* YHInformationPerfectCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInformationPerfectCell.swift; sourceTree = "<group>"; };
A5FD63C02B62616D00D1D9DA /* YHInformationPerfectModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInformationPerfectModel.swift; sourceTree = "<group>"; };
......@@ -2730,7 +2732,6 @@
04213B282C48EF5200797900 /* YHHomeInformationViewController.swift */,
04213B2E2C49154900797900 /* YHHomeInfoDetailContainerViewController.swift */,
04213B302C4917BD00797900 /* YHHomeInfoDetailViewController.swift */,
A59B43C82C491FB100B28379 /* YHEvaluationViewVC.swift */,
A59B43CA2C4A151200B28379 /* YHStatusAdvantageVC.swift */,
);
path = C;
......@@ -3078,6 +3079,7 @@
A5ACE91B2B4564F7002C94D2 /* Modules */ = {
isa = PBXGroup;
children = (
A5FD45212C523D3200908AD9 /* InteractionH5(与H5交互) */,
F8BAADA12C4FAE820074D6C3 /* UatModule(灰度功能) */,
044D0BE82C2019AC00C5CF5E /* Community(社区) */,
0499E3012C05B73D0037E646 /* AppleLogin(苹果登录) */,
......@@ -3198,6 +3200,15 @@
path = radar;
sourceTree = "<group>";
};
A5FD45212C523D3200908AD9 /* InteractionH5(与H5交互) */ = {
isa = PBXGroup;
children = (
A5FD45222C523DD300908AD9 /* YHJsApi.swift */,
A59B43C82C491FB100B28379 /* YHH5WebViewVC.swift */,
);
path = "InteractionH5(与H5交互)";
sourceTree = "<group>";
};
F8BAADA12C4FAE820074D6C3 /* UatModule(灰度功能) */ = {
isa = PBXGroup;
children = (
......@@ -3627,6 +3638,7 @@
0499E3002C056EE30037E646 /* YHOneKeyLoginView.swift in Sources */,
043D2C8C2C0F037B00172438 /* YHServiceOrderSearchViewModel.swift in Sources */,
0468D4262B495A5400CFB916 /* YHPickPhoneAddressViewController.swift in Sources */,
A5FD45232C523DD300908AD9 /* YHJsApi.swift in Sources */,
04213B292C48EF5300797900 /* YHHomeInformationViewController.swift in Sources */,
048B2A4D2BC7DAE800A93BF0 /* YHMyLikeViewModel.swift in Sources */,
04C693622B723AB8004C1758 /* YHMySettingViewController.swift in Sources */,
......@@ -3658,7 +3670,7 @@
A53B61192BB3C9960010B573 /* YHMyDocListHeaderView.swift in Sources */,
A567E5B22BD7643D00D5D5A0 /* YHHomeBannerCollectionViewCell.swift in Sources */,
045EEF082B9F171A0022A143 /* YHBasicInfoCellModel.swift in Sources */,
A59B43C92C491FB100B28379 /* YHEvaluationViewVC.swift in Sources */,
A59B43C92C491FB100B28379 /* YHH5WebViewVC.swift in Sources */,
0488518F2BF5FD1500C4E32D /* YHOSSManager.swift in Sources */,
A592FE952BA6D23C0062FACA /* YHCertificateEntryCell.swift in Sources */,
0419A09C2C48FBCB00A5FCFA /* YHInvitationWithGiftsHeadView.swift in Sources */,
......
......@@ -125,8 +125,10 @@ private extension YHStatusAdvantageVC {
bottomHoldView.block = { tag in
if tag == 0 {
//快速测评
let vc = YHEvaluationViewVC()
//跳转测评页
let vc = YHH5WebViewVC()
vc.url = YHBaseUrlManager.shared.curH5URL() + "superAppBridge/evaluation?from=app"
vc.isRightShareItemShareFlag = true
self.navigationController?.pushViewController(vc)
} else if tag == 1 {
if self.isQrInfoOk {
......
......@@ -139,12 +139,16 @@ extension YHLifeViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let model = self.viewModel.detailModel.products[indexPath.row]
let vc = YHEvaluationViewVC()
// todo 谢
let vc = YHH5WebViewVC()
// TODO: - 谢
vc.url = YHBaseUrlManager.shared.curH5URL() + "articleDetail.html" + "?id=\(model.id)"
vc.isWithBottomViewFlag = true
vc.isShareToMiniProgramFlag = true
vc.shareMiniPath = ""
self.navigationController?.pushViewController(vc)
}
}
extension YHLifeViewController: JXSegmentedListContainerViewListDelegate {
......
......@@ -65,8 +65,11 @@ class YHEvaluationView: UIView {
extension YHEvaluationView {
@objc func tapButton(gestureRecognizer:UITapGestureRecognizer) {
let vc = YHEvaluationViewVC()
self.parentViewController?.navigationController?.pushViewController(vc)
//跳转测评页
let vc = YHH5WebViewVC()
vc.url = YHBaseUrlManager.shared.curH5URL() + "superAppBridge/evaluation?from=app"
vc.isRightShareItemShareFlag = true
parentViewController?.navigationController?.pushViewController(vc)
}
func setupUI() {
......
......@@ -89,12 +89,11 @@ class YHServiceCenterMainViewController: YHBaseViewController {
noDataView.clickBackBtnClickBlock = {[weak self] in
guard self != nil else { return }
// let vc = YHHomeWebViewController()
// vc.vcTitle = "香港身份测评码"
// vc.showSavePicBottomFlag = true
// vc.url = "https://cdn-public.galaxy-immi.com/app/cepingma.png"
let vc = YHEvaluationViewVC()
//跳转测评页
let vc = YHH5WebViewVC()
vc.url = YHBaseUrlManager.shared.curH5URL() + "superAppBridge/evaluation?from=app"
vc.isRightShareItemShareFlag = true
self?.navigationController?.pushViewController(vc)
}
noDataView.clickShowBtnClickBlock = {
......
//
// YHEvaluationViewVC.swift
// YHH5WebViewVC.swift
// galaxy
//
// Created by davidhuangA on 2024/7/18.
......@@ -11,13 +11,13 @@ import WebKit
import dsBridge
/*
快速测评 及 需要与H5交互的界面
快速测评 及 其他与H5交互的界面
*/
class YHEvaluationViewVC: YHBaseViewController, WKUIDelegate, WKNavigationDelegate {
class YHH5WebViewVC: YHBaseViewController, WKUIDelegate, WKNavigationDelegate {
var webview = DWKWebView()
var progBar = UIProgressView()
var url = "https://www.baidu.com/"
var url = "https://test-hkdiy-h5.galaxy-immi.com/superAppBridge/evaluation?from=app"
lazy var noNetWorkTipsView: YHEmptyDataView = {
let view = YHEmptyDataView.createView("无网络", kNotNetWorkBgName)
view.topMargin = 222
......@@ -31,43 +31,93 @@ class YHEvaluationViewVC: YHBaseViewController, WKUIDelegate, WKNavigationDelega
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
deinit {
webview.removeObserver(self, forKeyPath: "estimatedProgress")
NotificationCenter.default.removeObserver(self)
}
//右上角分享按钮
var isRightShareItemShareFlag : Bool = false
//底部分享view
var isWithBottomViewFlag : Bool = false
lazy var shareView: YHShareViewOnTablebarView = {
let view = YHShareViewOnTablebarView()
view.isHidden = true
return view
}()
//分享到H5或者小程序
var isShareToMiniProgramFlag : Bool = false //是否分享到小程序 默认分享到h5
var shareMiniPath : String? //分享到小程序时的 path
//分享到H5的情况
var shareH5Title : String = "20秒极速测分"
var shareH5Describe : String = "您的朋友邀请您进行香港优才测评,来试试吧"
}
// MARK: - 内部方法
private extension YHH5WebViewVC {
func setupUI() {
gk_navBarAlpha = 1.0
gk_navLineHidden = false
#if DEBUG
// gk_navTitle = "快速测评"
#endif
NotificationCenter.default.addObserver(self, selector: #selector(updateNetWorkUI), name: .reachabilityChanged, object: nil)
view.backgroundColor = .white
//获取导航栏高度
let navHeight = self.navigationController?.navigationBar.frame.height
//获取状态栏高度
let statusHeight = k_Height_statusBar()
// 创建wkwebview
webview = DWKWebView(frame: CGRect(x: 0, y: statusHeight + navHeight!, width: self.view.frame.width, height: self.view.frame.height - statusHeight - navHeight! - 59 - k_Height_safeAreaInsetsBottom()))
if isWithBottomViewFlag {
view.addSubview(shareView)
}
shareView.block = { tag in
if tag == 0 {
//分享
self.share()
} else {
//预约咨询
// TODO: - for test hjl
// let codeUrl = model.codeUrl
// let downloadUrl = model.downloadUrl
// YHConsultantQRCodeView.codeView(codeUrl, downloadUrl: downloadUrl).show()
}
}
// 创建wkwebview
webview = DWKWebView(frame: .zero)
webview.scrollView.contentInsetAdjustmentBehavior = .never
webview.navigationDelegate = self
// 创建网址
if url.isYHEmpty() {
url = "https://www.baidu.com/"
}
webview.addJavascriptObject(YHJsApi(), namespace: nil)
let url = NSURL(string: url)
// 创建请求
let request = NSURLRequest(url: url! as URL)
// 加载请求
webview.load(request as URLRequest)
// 添加wkwebview
self.view.addSubview(webview)
webview.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
view.addSubview(webview)
webview.scrollView.contentInsetAdjustmentBehavior = .never
if isWithBottomViewFlag {
view.addSubview(shareView)
shareView.snp.makeConstraints { make in
make.bottom.left.right.equalToSuperview()
make.height.equalTo(YHShareViewOnTablebarView.viewH)
}
webview.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.bottom.equalTo(shareView.snp.top)
}
} else {
webview.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
// 加载网页的进度条
progBar = UIProgressView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 30))
......@@ -85,15 +135,6 @@ class YHEvaluationViewVC: YHBaseViewController, WKUIDelegate, WKNavigationDelega
updateNetWorkStatusUI(needReload: false)
}
deinit {
webview.removeObserver(self, forKeyPath: "estimatedProgress")
NotificationCenter.default.removeObserver(self)
}
}
// MARK: - 内部方法
private extension YHEvaluationViewVC {
func addRightItems() {
let rightButtonItem = UIBarButtonItem(image: UIImage(named: "share_item")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(share))
gk_navRightBarButtonItem = rightButtonItem
......@@ -102,7 +143,13 @@ private extension YHEvaluationViewVC {
@objc func share() {
YHShareManager.shared.sendLinkContent("20秒极速测分", "您的朋友邀请您进行香港优才测评,来试试吧", UIImage(named: "AppIcon") ?? UIImage(), link: url)
if self.isShareToMiniProgramFlag {
if let path = self.shareMiniPath,!path.isEmpty {
YHShareManager.shared.shareToMiniProgram(path:path, shareTitle: "请查看")
}
} else {
YHShareManager.shared.sendLinkContent(self.shareH5Title, self.shareH5Describe, UIImage(named: "AppIcon") ?? UIImage(), link: self.url)
}
}
@objc func updateNetWorkUI() {
......@@ -132,7 +179,6 @@ private extension YHEvaluationViewVC {
}
// MARK: - webview function
@objc func toBack() {
if webview.canGoBack {
webview.goBack()
......@@ -144,13 +190,11 @@ private extension YHEvaluationViewVC {
webview.goForward()
}
}
}
// MARK: - WKNavigationDelegate
extension YHEvaluationViewVC {
extension YHH5WebViewVC {
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
self.progBar.alpha = 1.0
......@@ -169,8 +213,11 @@ extension YHEvaluationViewVC {
override class func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
addRightItems()
if isRightShareItemShareFlag {
addRightItems()
}
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
......
//
// YHJsApi.swift
// dsbridgedemo
//
// Created by du on 2018/9/7.
// Copyright © 2018年 杜文. All rights reserved.
//
import Foundation
typealias JSCallback = (String, Bool)->Void
typealias JSDicCallback = ([String : Any],Bool)->Void
class YHJsApi: NSObject {
//MUST use "_" to ignore the first argument name explicitly。
@objc func testSyn( _ arg:String) {
printLog(arg)
}
@objc func testSynDic( _ arg:[String : Any]) {
print(arg)
return
}
@objc func testAsyn( _ arg:String, handler: JSCallback) {
handler(String(format:"%@[Swift async call:%@]", arg, "test"), true)
}
//同步方法
@objc func appMethodForJsSyn(_ arg:[String : Any]) {
}
//异步方法
@objc func appMethodForJsAsyn(_ arg:[String : Any],handler : JSDicCallback){
handler(["msg":1],true)
}
}
extension YHJsApi {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment