From 0a7cb7f5996c452db2aca158a1699a233368da31 Mon Sep 17 00:00:00 2001 From: bekannax Date: Sat, 8 Jul 2023 00:35:44 +0700 Subject: [PATCH] update --- .gitignore | 37 ---------- OnlineChatSdk.podspec | 4 +- OnlineChatSdk/Classes/ChatController.swift | 78 ++++++++++++++++++++-- 3 files changed, 73 insertions(+), 46 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 93c86d3..0000000 --- a/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -# OS X -.DS_Store - -# Xcode -build/ -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -xcuserdata/ -*.xccheckout -profile -*.moved-aside -DerivedData -*.hmap -*.ipa - -# Bundler -.bundle - -# Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts - -Carthage/Build - -# We recommend against adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control -# -# Note: if you ignore the Pods directory, make sure to uncomment -# `pod install` in .travis.yml -# -# Pods/ diff --git a/OnlineChatSdk.podspec b/OnlineChatSdk.podspec index a868689..76e8f6b 100644 --- a/OnlineChatSdk.podspec +++ b/OnlineChatSdk.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = 'OnlineChatSdk' - s.version = '0.0.8' + s.version = '0.1.7' s.summary = 'A small library containing a wrapper for the WKWebView.' s.swift_versions = '5.0' s.homepage = 'https://github.com/bekannax/OnlineChatSdk-Swift' s.license = { :type => 'MIT', :file => 'LICENSE' } s.authors = { 'bekannax' => 'bekannax@gmail.com' } s.source = { :git => 'https://github.com/bekannax/OnlineChatSdk-Swift.git', :tag => s.version.to_s } - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' s.source_files = 'OnlineChatSdk/Classes/**/*' end diff --git a/OnlineChatSdk/Classes/ChatController.swift b/OnlineChatSdk/Classes/ChatController.swift index ffedfe3..fd07341 100644 --- a/OnlineChatSdk/Classes/ChatController.swift +++ b/OnlineChatSdk/Classes/ChatController.swift @@ -35,6 +35,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa private var callJs: Array! private var didFinish: Bool = false private var widgetUrl: String = "" + private var widgetOrg: String = "" private var css: String = "" private static func getUnreadedMessagesCallback(_ result: NSDictionary) -> NSDictionary { @@ -164,11 +165,26 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa } public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ()) { +// print("widgetUrl = \(self.widgetUrl)") +// print("widgetOrg = \(self.widgetOrg)") +// print("absoluteString = \(navigationAction.request.url?.absoluteString)") if let _ = navigationAction.request.url?.host { + if (navigationAction.request.url?.absoluteString.contains(self.widgetOrg))! { + decisionHandler(.allow) + return + } if (navigationAction.request.url?.absoluteString.contains(self.widgetUrl))! { decisionHandler(.allow) return } + if ( + (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api2/anchor?" ))! || + (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api/fallback?" ))! || + (navigationAction.request.url?.absoluteString.contains( "https://www.google.com/recaptcha/api2/bframe?" ))! + ) { + decisionHandler(.allow) + return + } } decisionHandler(.cancel) onLinkPressed(url: navigationAction.request.url!) @@ -211,6 +227,55 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa return "{}" } +// public func load(_ id: String, _ domain: String, _ language: String = "", _ clientId: String = "", _ apiToken: String = "", _ showCloseButton: Bool = true, css: String = "") { +// if apiToken != "" { +// ChatConfig.setApiToken(apiToken) +// } +// var setup: Dictionary = [:] +// if !language.isEmpty { +// setup["language"] = language +// } +// if !clientId.isEmpty { +// setup["clientId"] = clientId +// } +// widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)" +// self.css = css +// var url = URL(string: widgetUrl) +// if url == nil { +// var encodeDomain = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)) +// encodeDomain = encodeDomain.replacingOccurrences(of: "Optional(\"", with: "") +// encodeDomain = encodeDomain.replacingOccurrences(of: "\")", with: "") +// widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(encodeDomain)" +// 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") +// ] +// } else { +// urlComponents?.queryItems = [ +// URLQueryItem(name: "setup", value: toJson(setup as AnyObject)) +// ] +// } +// } else { +// if (showCloseButton) { +// urlComponents?.queryItems = [ +// URLQueryItem(name: "sdk-show-close-button", value: "1") +// ] +// } +// } +// url = urlComponents!.url! +// if url == nil { +// url = URL(string: widgetUrl) +// } +// chatView.load(URLRequest(url: url!)) +// chatView.allowsBackForwardNavigationGestures = true +// } + + public func load(_ id: String, _ domain: String, _ language: String = "", _ clientId: String = "", _ apiToken: String = "", _ showCloseButton: Bool = true, css: String = "") { if apiToken != "" { ChatConfig.setApiToken(apiToken) @@ -222,16 +287,15 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa if !clientId.isEmpty { setup["clientId"] = clientId } - widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(domain)" self.css = css - var url = URL(string: widgetUrl) - if url == nil { - var encodeDomain = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)) + var encodeDomain: String = String(describing: domain.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)) + if (encodeDomain.contains("Optional(\"")) { encodeDomain = encodeDomain.replacingOccurrences(of: "Optional(\"", with: "") encodeDomain = encodeDomain.replacingOccurrences(of: "\")", with: "") - widgetUrl = "https://admin.verbox.ru/support/chat/\(id)/\(encodeDomain)" - url = URL(string: widgetUrl) } + 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) { @@ -269,7 +333,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa "var style = document.createElement('style');" + "style.type = 'text/css';" + "style.innerHTML = '\(style)';" + - "parent.appendChild(style);" + + "parent.appendChild(style) ;" + "})()"; callJs(injectCssTemplate);