From 6bad77723ec5291cb368684a71487da020644eb8 Mon Sep 17 00:00:00 2001 From: bekannax Date: Thu, 29 May 2025 19:39:39 +0700 Subject: [PATCH 1/5] 0.2.6 --- OnlineChatSdk/Classes/ChatController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index e6ee082..6507084 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -163,6 +163,9 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa let config = WKWebViewConfiguration() config.userContentController = contentController config.preferences = preferences + config.mediaPlaybackRequiresUserAction = false + config.allowsInlineMediaPlayback = true + var frame = UIScreen.main.bounds if parent != nil && parent?.view != nil && parent?.view.bounds != nil { @@ -631,4 +634,4 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa open func getContactsCallback(_ data: NSDictionary) { } -} \ No newline at end of file +} From b3aaf4e42f1750cb1dc3567b04cff7f81c6763f7 Mon Sep 17 00:00:00 2001 From: bekannax Date: Thu, 29 May 2025 19:54:24 +0700 Subject: [PATCH 2/5] 0.2.6 --- OnlineChatSdk/Classes/ChatController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index 6507084..9728514 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -165,7 +165,6 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa config.preferences = preferences config.mediaPlaybackRequiresUserAction = false config.allowsInlineMediaPlayback = true - var frame = UIScreen.main.bounds if parent != nil && parent?.view != nil && parent?.view.bounds != nil { From 8dac77cc954474f61b225d1b04e370f17671804e Mon Sep 17 00:00:00 2001 From: bekannax Date: Tue, 10 Jun 2025 11:28:55 +0700 Subject: [PATCH 3/5] 0.2.7 --- OnlineChatSdk/Classes/ChatController.swift | 56 ++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index 9728514..0403b43 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -39,6 +39,8 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa private var widgetOrg: String = "" private var css: String = "" private var alertLoading: UIAlertController? + private let logTag = "OnlineChatSdk" + private var isOnCloseSupport = false private static func getUnreadedMessagesCallback(_ result: NSDictionary) -> NSDictionary { let resultWrapper = ChatApiMessagesWrapper(result) @@ -307,7 +309,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } private func callJs(_ script: String) { - print("callJs : \(script)") + print("\(logTag) :: callJs :: \(script)") chatView.evaluateJavaScript(script) } @@ -384,36 +386,44 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } self.css = css var encodeDomain: String = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)) - if (encodeDomain.contains("Optional(\"")) { + if encodeDomain.contains("Optional(\"") { encodeDomain = encodeDomain.replacingOccurrences(of: "Optional(\"", with: "") encodeDomain = encodeDomain.replacingOccurrences(of: "\")", with: "") } widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(encodeDomain)" widgetOrg = "https://admin.verbox.ru/support/chat/\(id)/" var url = URL(string: widgetUrl) - var urlComponents = URLComponents(url: url!, resolvingAgainstBaseURL: false) - if !setup.isEmpty { - if (showCloseButton) { - urlComponents?.queryItems = [ - URLQueryItem(name: "setup", value: toJson(setup as AnyObject)), - URLQueryItem(name: "sdk-show-close-button", value: "1") - ] + if url != nil { + var urlComponents = URLComponents(url: url!, resolvingAgainstBaseURL: false) + if !setup.isEmpty { + if (showCloseButton) { + urlComponents?.queryItems = [ + URLQueryItem(name: "setup", value: toJson(setup as AnyObject)), + URLQueryItem(name: "sdk-show-close-button", value: "1") + ] + } else { + urlComponents?.queryItems = [ + URLQueryItem(name: "setup", value: toJson(setup as AnyObject)) + ] + } } else { - urlComponents?.queryItems = [ - URLQueryItem(name: "setup", value: toJson(setup as AnyObject)) - ] - } - } else { - if (showCloseButton) { - urlComponents?.queryItems = [ - URLQueryItem(name: "sdk-show-close-button", value: "1") - ] + if (showCloseButton) { + urlComponents?.queryItems = [ + URLQueryItem(name: "sdk-show-close-button", value: "1") + ] + } } + url = urlComponents!.url } - url = urlComponents!.url! if url == nil { url = URL(string: widgetUrl) } + if url == nil { + DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { + self.showMessage("url=\(self.widgetUrl) not init") + } + return + } chatView.load(URLRequest(url: url!)) chatView.allowsBackForwardNavigationGestures = true } @@ -478,6 +488,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } private func callJsDestroy() { + print("\(logTag) :: callJsDestroy") callJsMethod(ChatController.method_destroy, params: []) } @@ -539,6 +550,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa default: break } + print("\(logTag) :: userContentController :: \(data!)") onEvent(name, data!) } @@ -575,9 +587,15 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } open func onCloseSupport() { + if (isOnCloseSupport) { + return + } + isOnCloseSupport = true + print("\(logTag) :: onCloseSupport :: 1") if chatView == nil { return } + print("\(logTag) :: onCloseSupport :: 2") chatView.stopLoading() callJsDestroy() chatView = nil From f9a46ebc8d73e700af5a9a94c3e3beb50d1ea711 Mon Sep 17 00:00:00 2001 From: bekannax Date: Tue, 10 Jun 2025 17:25:27 +0700 Subject: [PATCH 4/5] 0.2.8 --- OnlineChatSdk/Classes/ChatController.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index 0403b43..f655b57 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -176,6 +176,8 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa chatView.navigationDelegate = self view = chatView + + print("\(logTag) :: loadView") } private func getAlertLoadingActionCloseTitle() -> String { @@ -228,16 +230,19 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { showLoadingDialog() + print("\(logTag) :: webView :: didStartProvisionalNavigation") } public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { hideLoadingDialog() showMessage(error.localizedDescription) + print("\(logTag) :: webView :: didFail") } public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: any Error) { hideLoadingDialog() showMessage(error.localizedDescription) + print("\(logTag) :: webView :: didFailProvisionalNavigation") } private func showMessage(_ message: String) { @@ -260,16 +265,19 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } callJs = nil } + print("\(logTag) :: webView :: didFinish") // hideLoadingDialog() } public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ()) { if let _ = navigationAction.request.url?.host { if (navigationAction.request.url?.absoluteString.contains(self.widgetOrg))! { + print("\(logTag) :: webView :: navigationAction :: 1 :: \(navigationAction.request.url)") decisionHandler(.allow) return } if (navigationAction.request.url?.absoluteString.contains(self.widgetUrl))! { + print("\(logTag) :: webView :: navigationAction :: 2 :: \(navigationAction.request.url)") decisionHandler(.allow) return } @@ -278,10 +286,12 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api/fallback?" ))! || (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api2/bframe?" ))! ) { + print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url)") decisionHandler(.allow) return } } + print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url)") decisionHandler(.cancel) onLinkPressed(url: navigationAction.request.url!) } @@ -374,6 +384,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa public func load(_ id: String, _ domain: String, _ language: String = "", _ clientId: String = "", _ apiToken: String = "", _ showCloseButton: Bool = true, css: String = "") { + print("\(logTag) :: load :: 1") if apiToken != "" { ChatConfig.setApiToken(apiToken) } @@ -426,6 +437,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } chatView.load(URLRequest(url: url!)) chatView.allowsBackForwardNavigationGestures = true + print("\(logTag) :: load :: 2") } public func injectCss(style: String) { From 843dca6123c07daac2d49f91d5bc89dbf9d88e5b Mon Sep 17 00:00:00 2001 From: bekannax Date: Tue, 10 Jun 2025 19:50:34 +0700 Subject: [PATCH 5/5] 0.2.9 --- OnlineChatSdk/Classes/ChatController.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index f655b57..6bd9165 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -270,14 +270,19 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ()) { + if navigationAction.request.url == nil { + print("\(logTag) :: webView :: navigationAction :: 0") + decisionHandler(.cancel) + return + } if let _ = navigationAction.request.url?.host { if (navigationAction.request.url?.absoluteString.contains(self.widgetOrg))! { - print("\(logTag) :: webView :: navigationAction :: 1 :: \(navigationAction.request.url)") + print("\(logTag) :: webView :: navigationAction :: 1 :: \(navigationAction.request.url!)") decisionHandler(.allow) return } if (navigationAction.request.url?.absoluteString.contains(self.widgetUrl))! { - print("\(logTag) :: webView :: navigationAction :: 2 :: \(navigationAction.request.url)") + print("\(logTag) :: webView :: navigationAction :: 2 :: \(navigationAction.request.url!)") decisionHandler(.allow) return } @@ -286,12 +291,12 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api/fallback?" ))! || (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api2/bframe?" ))! ) { - print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url)") + print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url!)") decisionHandler(.allow) return } } - print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url)") + print("\(logTag) :: webView :: navigationAction :: 3 :: \(navigationAction.request.url!)") decisionHandler(.cancel) onLinkPressed(url: navigationAction.request.url!) } @@ -621,7 +626,8 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa open override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - onCloseSupport() +// onCloseSupport() + print("\(logTag) :: viewDidDisappear") } open func onLinkPressed(url: URL) {