3

I want to use TinyMCE rich text editor for my iOS app that I wrote in Swift.

I want to access self-hosted locally from xCode with tinymce.min.js.

I did everything according to the guide but style and javascript is not working, i am only displaying a textbox without toolbar.

I would appreciate it if anyone who has installed it before can help.

NOTE: it works when I try with api key. But I want to run it via xCode not via url

Code like below:

<!DOCTYPE html>
<html>
<head><!-- Get TinyMCe Cloud -->
<script src="js/tinymce/tinymce.min.js"></script>
<script>
  tinymce.init({
    selector: 'textarea',
    theme: 'silver',
    mobile: {
      theme: 'mobile',
      plugins: 'autosave lists autolink',
      toolbar: 'undo bold italic styleselect'
    }
  });
  </script>

  </head>
  <body>
  <textarea>Now go get a free trial of our Premium Plugins!</textarea>

  </body>
  </html>

enter image description here

SwiftTry
  • 121
  • 10

1 Answers1

0

I run this script

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    if let filePath = Bundle.main.url(forResource: "assets/tinyeditor", withExtension: "html") {
        let request = URLRequest(url: filePath)
        webView.load(request)
    }
}

public func runJS(_ js: String, handler: ((String) -> Void)? = nil) {
    webView.evaluateJavaScript(js) {(result, error) in
        if let error = error {
            print("WKWebViewJavascriptBridge Error: \(String(describing: error)) - JS: \(js)")
            handler?("")
            return
        }
        
        guard let handler = handler else { return }
        if let resultStr = result as? String {
            handler(resultStr)
            return
        }
        handler("") // no result
    }
}

@IBAction func getHtmlTap(_ sender: Any) {
    runJS("tinymce.activeEditor.getContent();", handler: {[weak self] html in
        self?.showAlertView(html)
    })
}

You can try my variant enter link description here

  • Please do not post images of code, copy your code into the question with block code format: https://stackoverflow.com/help/how-to-ask – borchvm Mar 01 '23 at 10:22