Browse Source

首页活动点击链接处理

culturetown 3 weeks ago
parent
commit
a75c03d612

+ 4 - 0
Koala/Koala.xcodeproj/project.pbxproj

@@ -60,6 +60,7 @@
 		0412A4B02C58AD1B007E42BF /* JDFuncLimitPopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0412A4AF2C58AD1B007E42BF /* JDFuncLimitPopView.swift */; };
 		0412A4B42C58BE2C007E42BF /* JDFuncLimitDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0412A4B32C58BE2C007E42BF /* JDFuncLimitDetailViewController.swift */; };
 		04177EED2C7339560043C10B /* JDMineNewInvitePopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04177EEC2C7339560043C10B /* JDMineNewInvitePopView.swift */; };
+		04177EF12C78E01A0043C10B /* JDActivityWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04177EF02C78E01A0043C10B /* JDActivityWebViewController.swift */; };
 		041D4EE42ABEBA0C008ABDF7 /* JDAFiatAccountListPopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041D4EE32ABEBA0C008ABDF7 /* JDAFiatAccountListPopView.swift */; };
 		041D4EE82ABFE4D6008ABDF7 /* JDRecipientCurrencyListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041D4EE72ABFE4D6008ABDF7 /* JDRecipientCurrencyListViewController.swift */; };
 		041D4EEA2AC14E20008ABDF7 /* JDSearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041D4EE92AC14E20008ABDF7 /* JDSearchBarView.swift */; };
@@ -1248,6 +1249,7 @@
 		0412A4AF2C58AD1B007E42BF /* JDFuncLimitPopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDFuncLimitPopView.swift; sourceTree = "<group>"; };
 		0412A4B32C58BE2C007E42BF /* JDFuncLimitDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDFuncLimitDetailViewController.swift; sourceTree = "<group>"; };
 		04177EEC2C7339560043C10B /* JDMineNewInvitePopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDMineNewInvitePopView.swift; sourceTree = "<group>"; };
+		04177EF02C78E01A0043C10B /* JDActivityWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDActivityWebViewController.swift; sourceTree = "<group>"; };
 		041D4EE32ABEBA0C008ABDF7 /* JDAFiatAccountListPopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDAFiatAccountListPopView.swift; sourceTree = "<group>"; };
 		041D4EE72ABFE4D6008ABDF7 /* JDRecipientCurrencyListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDRecipientCurrencyListViewController.swift; sourceTree = "<group>"; };
 		041D4EE92AC14E20008ABDF7 /* JDSearchBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JDSearchBarView.swift; sourceTree = "<group>"; };
@@ -3405,6 +3407,7 @@
 				045E7E002B6A1548008987BA /* JDNoticeNewsListViewController.swift */,
 				6C7A1AE829F80797004CFBE3 /* CreditsViewController.swift */,
 				6C7A1AE929F80797004CFBE3 /* CreditsViewController.xib */,
+				04177EF02C78E01A0043C10B /* JDActivityWebViewController.swift */,
 			);
 			path = VC;
 			sourceTree = "<group>";
@@ -5750,6 +5753,7 @@
 				6CA7132A2958136E0047F450 /* HMSegmentedControl.m in Sources */,
 				049F2E452C58E06D00649DCA /* JDIdentityFormViewController.swift in Sources */,
 				6C00A94B2432F1E200CE9ADB /* ScanCodeViewController.swift in Sources */,
+				04177EF12C78E01A0043C10B /* JDActivityWebViewController.swift in Sources */,
 				6C7A1AE729F6D052004CFBE3 /* HomeMarketPopView.swift in Sources */,
 				6C0C49A6295F287C000BFEEB /* BindAccountCell.swift in Sources */,
 				6C50AB592A03E4FA00699557 /* DealSimplenessCell.swift in Sources */,

+ 34 - 18
Koala/Koala.xcworkspace/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -478,8 +478,8 @@
             filePath = "Koala/Modular/JDMine/VC/JDMineInviteShareViewController.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "277"
-            endingLineNumber = "277"
+            startingLineNumber = "279"
+            endingLineNumber = "279"
             landmarkName = "unknown"
             landmarkType = "0">
          </BreakpointContent>
@@ -1103,22 +1103,6 @@
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
-            uuid = "BABBA710-634A-46F0-9D1B-7DEE961700CE"
-            shouldBeEnabled = "No"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "Koala/Modular/Public/VC/WebView/BaseWebViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "334"
-            endingLineNumber = "334"
-            landmarkName = "webView(_:decidePolicyFor:decisionHandler:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
             uuid = "7F274D16-0770-4315-BB4D-B6E8D184288C"
             shouldBeEnabled = "No"
             ignoreCount = "0"
@@ -1708,5 +1692,37 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "DBBB783C-5CCE-4BCE-A9EB-2EEC2D1E3D0C"
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "Koala/Modular/Home/V/HomeNewUI/HomeActivityCell.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "286"
+            endingLineNumber = "286"
+            landmarkName = "didSelectCell(subView:subViewIndex:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "61B66BF2-7DE5-4C3F-9D0D-94C9D67DB563"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "Koala/Modular/Public/VC/WebView/BaseWebViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "288"
+            endingLineNumber = "288"
+            landmarkName = "webView(_:decidePolicyFor:decisionHandler:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 28 - 5
Koala/Koala/Modular/Home/V/HomeNewUI/HomeActivityCell.swift

@@ -261,13 +261,36 @@ extension HomeActivityCell: PageFlowViewDelegate, PageFlowViewDataSource {
     }
     
     func didSelectCell(subView: IndexBannerSubiew, subViewIndex subIndex: Int) {
+        
+        guard OperationalUserInfoData.getLogin() else {
+            currentVc()?.navigationController?.pushViewController(JDLoginViewController(), animated: true)
+            return
+        }
+
+        
         if let banner = subView as? HomeActivityBannerSubiew {
-            let vc = BaseWebViewController()
+            
             let model = banner.item
-            vc.url = model?.url ?? ""
-            vc.title = model?.title ?? ""
-            vc.myNavigationBar.title_Label.text = switchLanguage("活动详情")
-            currentVc()?.navigationController?.pushViewController(vc, animated: true)
+            let url = model!.url + "?flag=app&token="+OperationalUserInfoData.getToken()
+            
+            
+            if url.contains("/share") {
+                
+     
+                let vc = JDMineInviteShareViewController()
+                currentVc()?.navigationController?.pushViewController(vc, animated: true)
+                
+            }else {
+                
+                
+                let vc = JDActivityWebViewController()
+                
+                print(url)
+                vc.url = url //model?.url ?? ""
+                //            vc.title = model?.title ?? ""
+                vc.myNavigationBar.title_Label.text = switchLanguage("活动详情")
+                currentVc()?.navigationController?.pushViewController(vc, animated: true)
+            }
         }
     }
     

+ 183 - 0
Koala/Koala/Modular/Home/VC/JDActivityWebViewController.swift

@@ -0,0 +1,183 @@
+//
+//  JDActivityWebViewController.swift
+//  Koala
+//
+//  Created by mac on 2024/8/23.
+//  Copyright © 2024 Koala. All rights reserved.
+//
+
+import SafariServices
+import UIKit
+import WebKit
+
+class JDActivityWebViewController: BaseViewController {
+
+    var webView: WKWebView!
+    var config: WKWebViewConfiguration!
+    
+    var webReady: Bool! = false
+  
+    var url: String! = ""
+    var navTitle : String = switchLanguage("活动详情")
+   
+    /// 添加进度条
+    lazy var progressView: UIProgressView = {
+        self.progressView = UIProgressView(frame: CGRect(x: 0, y: TopHeight, width: SCREEN_WIDTH, height: 2))
+        self.progressView.tintColor = MainBackGroundColor // 进度条颜色
+        self.progressView.trackTintColor = ViewBorderColor // 进度条背景色
+        return self.progressView
+    }()
+    
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        myNavigationBar.title_Label.text =  navTitle
+//        self.myNavigationBar.title_Label.textColor = .white
+//        self.myNavigationBar.left_Button.setImage(_image("Base_White_Back&Base_White_Back"), for: .normal)
+//        self.myNavigationBar.backgroundColor = .clear
+//        self.myNavigationBar.back_ImageView.isHidden = true
+//        self.myNavigationBar.left_ImageView.isHidden = true
+//        self.myNavigationBar.left_SuperView.backgroundColor = .clear
+
+//        switch GlobalSingle.sharedInstance.currentLan {
+//            case .EnglishLanguage:
+//                url = "https://m.jdnx2.com/en/share?flag=app&token="+OperationalUserInfoData.getToken()
+//            case .TraditionalLanguage:
+//                url = "https://m.jdnx2.com/zh-TW/share?flag=app&language=zh_TW&token="+OperationalUserInfoData.getToken()
+//            case .ChineseLanguage:
+//                url = "https://m.jdnx2.com/zh-CN/share?flag=app&language=zh_CN&token="+OperationalUserInfoData.getToken()
+//            default:
+////                vc.url = JoinENUrl+OperationalUserInfoData.getUserInfoDataModel().uid+"?flag=app"
+//                url = "https://m.jdnx2.com/en/share?flag=app&language=en&token="+OperationalUserInfoData.getToken()
+//        }
+        
+        print(url)
+        
+//        url = "https://m.jdnx.com/share?flag=app&token="+OperationalUserInfoData.getToken()
+
+        if url.count > 0 {
+            var charSet = CharacterSet.urlQueryAllowed
+            charSet.insert(charactersIn: "#")
+            if let u = URL(string: url.addingPercentEncoding(withAllowedCharacters: charSet)!) {
+                let js = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"
+                let userScript = WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false)
+                let config = WKWebViewConfiguration()
+                config.userContentController.addUserScript(userScript)
+                config.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
+                config.websiteDataStore = WKWebsiteDataStore.default()
+                //                webView = WKWebView(frame: CGRect(x: 0, y: TopHeight, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-TopHeight-KBottomMargin), configuration: config)
+                
+                webView = WKWebView(frame: .zero, configuration: config)
+                
+                webView.backgroundColor = .clear
+                webView.isOpaque = false
+                webView.navigationDelegate = self
+                view.addSubview(webView)
+           
+                webView.load(URLRequest(url: u))
+                webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)
+                
+                view.bringSubviewToFront(myNavigationBar)
+//                return
+            }
+        }
+        
+        view.addSubview(progressView)
+        view.bringSubviewToFront(progressView) // 将进度条至于最顶层
+    }
+    
+    override func viewWillLayoutSubviews() {
+        super.viewWillLayoutSubviews()
+        
+//        bottomView.snp.makeConstraints { make in
+//            make.left.right.bottom.equalTo(self.view)
+//            make.height.equalTo(136)
+//        }
+        
+        webView.snp.makeConstraints { make in
+            make.left.right.equalToSuperview()
+            make.top.equalTo(self.myNavigationBar.snp.bottom)
+            make.bottom.equalTo(self.view.snp.bottom)
+        }
+    }
+}
+
+extension JDActivityWebViewController: WKScriptMessageHandler {
+    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
+        //  加载进度条
+        if keyPath == "estimatedProgress" {
+            progressView.alpha = 1.0
+            progressView.setProgress(Float(webView.estimatedProgress), animated: true)
+            if (webView.estimatedProgress) >= 1.0 {
+                UIView.animate(withDuration: 0.3, delay: 0.1, options: .curveEaseOut, animations: {
+                    self.progressView.alpha = 0
+                }, completion: { _ in
+                    self.progressView.setProgress(0.0, animated: false)
+                })
+            }
+        }
+    }
+    
+    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
+//        if let actionDic = message.body as? NSDictionary {
+//            if let action = actionDic["name"] as? String {
+//                switch action {
+//                case "logout": // MARK: 退出登录
+//                    logout(isWeb:true)
+//                default:
+//                    Dlog("")
+//                }
+//            }
+//        }
+    }
+}
+
+extension JDActivityWebViewController: WKNavigationDelegate {
+    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
+        if let url: URL = navigationAction.request.url {
+            if url.absoluteString.hasPrefix("itms-appss://") || url.absoluteString.hasPrefix("itms-apps://") {
+                if UIApplication.shared.canOpenURL(url) {
+                    if #available(iOS 10, *) {
+                        UIApplication.shared.open(url, options: [:], completionHandler: {
+                            _ in
+                        })
+                    } else {
+                        UIApplication.shared.canOpenURL(url)
+                    }
+                    decisionHandler(.cancel)
+                    return
+                }
+            } else {
+                print(url.absoluteString)
+                if UIApplication.shared.canOpenURL(url) && (url.absoluteString == "https://agent.jdnx.com/") {
+                    let safariVC = SFSafariViewController(url: url)
+                    currentVc()?.navigationController?.present(safariVC, animated: true, completion: nil)
+                    decisionHandler(.cancel)
+                    return
+                } else if UIApplication.shared.canOpenURL(url) && self.url.length == 0 {
+                    let safariVC = SFSafariViewController(url: url)
+                    currentVc()?.navigationController?.present(safariVC, animated: true, completion: nil)
+                    decisionHandler(.cancel)
+                    return
+                }
+            }
+        }
+        decisionHandler(.allow)
+    }
+    
+    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
+//        ProgressHUD.showGIFLoading()
+    }
+    
+    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
+//        ProgressHUD.hideHud()
+//        ProgressHUD.dismissGIFHud()
+    }
+    
+    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
+//        ProgressHUD.dismissGIFHud()
+    }
+    
+    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
+//        ProgressHUD.dismissGIFHud()
+    }
+}

+ 2 - 0
Koala/Koala/Modular/JDMine/VC/JDMineInviteShareViewController.swift

@@ -54,6 +54,8 @@ class JDMineInviteShareViewController: BaseViewController {
                 url = "https://m.jdnx2.com/en/share?flag=app&language=en&token="+OperationalUserInfoData.getToken()
         }
         
+        print(url)
+        
 //        url = "https://m.jdnx.com/share?flag=app&token="+OperationalUserInfoData.getToken()
         view.addSubview(bottomView)