HelpViewController.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import UIKit
  2. import WebKit
  3. class HelpViewController: WebViewViewController {
  4. override func viewDidLoad() {
  5. super.viewDidLoad()
  6. view.backgroundColor = .white
  7. self.title = String.localized("menu_help")
  8. }
  9. override func viewWillAppear(_ animated: Bool) {
  10. super.viewWillAppear(animated)
  11. loadHtmlContent { [weak self] url in
  12. // return to main thread
  13. DispatchQueue.main.async {
  14. self?.webView.loadFileURL(url, allowingReadAccessTo: url)
  15. }
  16. }
  17. }
  18. private func loadHtmlContent(completionHandler: ((URL) -> Void)?) {
  19. // execute in background thread because file loading would blockui for a few milliseconds
  20. DispatchQueue.global(qos: .background).async {
  21. let lang = Utils.getDeviceLanguage() ?? "en" // en is backup
  22. var fileURL: URL?
  23. fileURL = Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/\(lang)") ??
  24. Bundle.main.url(forResource: "help", withExtension: "html", subdirectory: "Assets/Help/en")
  25. guard let url = fileURL else {
  26. safe_fatalError("could not find help asset")
  27. return
  28. }
  29. completionHandler?(url)
  30. }
  31. }
  32. }