123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import Foundation
- class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
-
- @IBOutlet weak var webView: WKWebView!
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- @objc var metadata: tableMetadata!
- @objc var link: String = ""
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
-
-
- var request = URLRequest(url: URL(string: link)!)
- request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")
- let language = NSLocale.preferredLanguages[0] as String
- request.addValue(language, forHTTPHeaderField: "Accept-Language")
-
- let userAgent : String = CCUtility.getUserAgent()
- self.webView.customUserAgent = userAgent
- self.webView.load(request)
- }
-
- @objc func keyboardDidShow(notification: Notification) {
-
- }
-
- @objc func keyboardWillHide(notification: Notification) {
-
- }
-
-
- public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
-
- if (message.name == "DirectEditingMobileInterface") {
-
- if message.body as? String == "close" {
-
- appDelegate.activeMain.readFileReloadFolder()
- }
-
- if message.body as? String == "share" {
- NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 2)
- }
-
- if message.body as? String == "loading" {
- print("loading")
- }
-
- if message.body as? String == "loaded" {
- print("loaded")
- }
-
- if message.body as? String == "paste" {
- self.paste(self)
- }
- }
- }
-
-
-
- public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil);
- }
- }
-
- public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
- print("didStartProvisionalNavigation");
- }
-
- public func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
- print("didReceiveServerRedirectForProvisionalNavigation");
- }
-
- public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
- NCUtility.sharedInstance.stopActivityIndicator()
- }
- }
|