Interactive Ink

Loading note in code

I'm trying to export/share a bunch of notes at once and I believe the only way to do so is to load each note with the engine, package etc. and then export each one with the built in function.

Do I have to do so with visible view controllers? I've tried just extracting the core elements of loading a note, but it doesn't seem to work. My code is below.


  

        for cell in selectedCells{
            
            var currentPackage: IINKContentPackage?
            var editorViewController: EditorViewController?
            let engine: IINKEngine? = createEngine()
            // Open it

            let path = FileManager.default.iinkDirectory()+"/"+cell
            do{ try currentPackage = engine?.openPackage((path.decomposedStringWithCanonicalMapping)) } catch{ print ("error") }
            
            editorViewController = self.parent?.childViewControllers[0] as? EditorViewController
            let rootViewController = UIApplication.shared.keyWindow?.rootViewController as? MainNavigationViewController
            editorViewController?.engine = rootViewController?.engine
            
            let editor: IINKEditor? = editorViewController?.editor
            
            // Reset viewing parameters
            editor?.renderer.viewScale = 1
            editor?.renderer.viewOffset = CGPoint(x: 0, y: 0)
            // Bind the part to the editor
            editor?.setViewSize (CGSize(width: view.bounds.size.width, height: view.bounds.size.height), error: nil)
            do {
                try editor?.part = currentPackage?.getPartAt(0)
            } catch {
                print("error")
            }
            let jsonText = try? editorViewController?.editor.export_(editorViewController?.editor.rootBlock, mimeType: IINKMimeType.JIIX)
            print(jsonText)

}

 

Thanks,

Ethan 


Addendum: I don't get any error message, but the jsonText is nil.

Dear Ethan,


thank you for your question.


I am a bit puzzled your JSON is nill... Is it possible to get a package, so that we can try to reproduce?


To answer your question, you do not need to set a UI part for your use-case. Also, we recommend you do not re-create the engine each time but only once (before your loop "for cell in selectedCells").


Best regards,


Olivier

Login or Signup to post a comment