From 161a1294077e2773dd552d3e926598b315e71ca5 Mon Sep 17 00:00:00 2001 From: Gabriel Wong Date: Mon, 11 Dec 2017 12:42:49 +0700 Subject: [PATCH] Fix samples --- .../KMEI/KeymanEngine/Classes/Manager.swift | 1 + .../KMSample1/KMSample1/ViewController.swift | 22 ++++++++++-------- .../KMSample2/KMSample2/ViewController.swift | 23 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift index 1cc4b96ec0..d157a4365a 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Manager.swift @@ -698,6 +698,7 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat /// Preloads the JS and font files required for a keyboard. public func preloadFiles(forKeyboardID keyboardID: String, at urls: [URL], shouldOverwrite: Bool) throws { let keyboardDir = Storage.active.keyboardDir(forID: keyboardID) + try FileManager.default.createDirectory(at: keyboardDir, withIntermediateDirectories: true) for url in urls { try Storage.copyAndExcludeFromBackup(at: url, to: keyboardDir.appendingPathComponent(url.lastPathComponent), diff --git a/ios/samples/KMSample1/KMSample1/ViewController.swift b/ios/samples/KMSample1/KMSample1/ViewController.swift index 7172846fe2..b6b9b64667 100644 --- a/ios/samples/KMSample1/KMSample1/ViewController.swift +++ b/ios/samples/KMSample1/KMSample1/ViewController.swift @@ -15,17 +15,7 @@ class ViewController: UIViewController, TextViewDelegate { super.viewDidLoad() Manager.shared.openURL = UIApplication.shared.openURL Manager.shared.isKeymanHelpOn = false - do { - try Manager.shared.preloadKeyboardFile(at: Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!, - shouldOverwrite: true) - try Manager.shared.preloadFontFile(at: Bundle.main.url(forResource: "aava1", withExtension: "ttf")!, - shouldOverwrite: true) - } catch { - print("Error preloading: \(error)") - } - FontManager.shared.registerCustomFonts() - Manager.shared.addKeyboard(Defaults.keyboard) let kb = InstallableKeyboard(id: "tamil99m", name: "Tamil 99M", languageID: "tam", @@ -35,6 +25,18 @@ class ViewController: UIViewController, TextViewDelegate { font: Font(filename: "aava1.ttf"), oskFont: nil, isCustom: true) + let urls = [ + Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!, + Bundle.main.url(forResource: "aava1", withExtension: "ttf")! + ] + do { + try Manager.shared.preloadFiles(forKeyboardID: kb.id, at: urls, shouldOverwrite: true) + } catch { + print("Error preloading: \(error)") + } + FontManager.shared.registerCustomFonts() + + Manager.shared.addKeyboard(Defaults.keyboard) Manager.shared.addKeyboard(kb) textView.setKeymanDelegate(self) diff --git a/ios/samples/KMSample2/KMSample2/ViewController.swift b/ios/samples/KMSample2/KMSample2/ViewController.swift index c67e75cba9..5cdb44657f 100644 --- a/ios/samples/KMSample2/KMSample2/ViewController.swift +++ b/ios/samples/KMSample2/KMSample2/ViewController.swift @@ -16,19 +16,8 @@ class ViewController: UIViewController, TextViewDelegate { super.viewDidLoad() Manager.shared.openURL = UIApplication.shared.openURL - Manager.shared.isKeymanHelpOn = false - do { - try Manager.shared.preloadKeyboardFile(at: Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!, - shouldOverwrite: true) - try Manager.shared.preloadFontFile(at: Bundle.main.url(forResource: "aava1", withExtension: "ttf")!, - shouldOverwrite: true) - } catch { - print("Error preloading: \(error)") - } - FontManager.shared.registerCustomFonts() - Manager.shared.addKeyboard(Defaults.keyboard) let kb = InstallableKeyboard(id: "tamil99m", name: "Tamil 99M", languageID: "tam", @@ -38,6 +27,18 @@ class ViewController: UIViewController, TextViewDelegate { font: Font(filename: "aava1.ttf"), oskFont: nil, isCustom: true) + let urls = [ + Bundle.main.url(forResource: "tamil99m-1.1", withExtension: "js")!, + Bundle.main.url(forResource: "aava1", withExtension: "ttf")! + ] + do { + try Manager.shared.preloadFiles(forKeyboardID: kb.id, at: urls, shouldOverwrite: true) + } catch { + print("Error preloading: \(error)") + } + FontManager.shared.registerCustomFonts() + + Manager.shared.addKeyboard(Defaults.keyboard) Manager.shared.addKeyboard(kb) textView.setKeymanDelegate(self)