Interactive Ink

Getting Error, -[IINKEngine createPackage:error:]::108 io error while creating the package

I've been trying to use the iink runtime in an existing iOS app but did not have any luck so far.

What does the error "Error, -[IINKEngine createPackage:error:]::108 io error" mean? Is there any documentation?

Thanks!


Hi,

An "IO error" thrown by this method usually means that iink SDK was unable to create the file corresponding to the package on the disk. A common root cause is attempting to write into a location that is not authorized (for instance, if you just specify a file name as a path, iink SDK will see it as a relative path and attempt to write close to your executable, which is not allowed by iOS). Do you have the read/write rights for the location where you want to create the package?

The following code snippet (from the examples), allows creating a package called "<name>.iink" inside the document directory of the application bundle:

// The "name" variable contains the name of the file to write to the Document folder
NSString *fullPath = [[[NSFileManager defaultManager] pathForFileInDocumentDirectory:name] stringByAppendingPathExtension:@"iink"];
IINKContentPackage *package = [engine createPackage:fullPath.decomposedStringWithCanonicalMapping error:nil];

Please tell us if it helps,

Best regards,

Thomas

Hi Thomas, thanks for the quick response!

Sorry for not posting any code, here is how I do it:

    func createPackage(packageName: String) throws -> IINKContentPackage? {
        // Create a new content package with name
        var resultPackage: IINKContentPackage?
        let urlWithExtension = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(packageName, isDirectory: false).appendingPathExtension("iink")

        try! FileManager.default.createDirectory(at: urlWithExtension.deletingLastPathComponent(), withIntermediateDirectories: true, attributes: nil)
        let fullPath = urlWithExtension.absoluteString
        if let engine = engine {
            resultPackage = try engine.createPackage(fullPath.decomposedStringWithCanonicalMapping)

            // Add a blank page type Text Document
            if let part = try resultPackage?.createPart("Text Document") /* Options are : "Diagram", "Drawing", "Math", "Text Document", "Text" */ {
                print("All's fine")
            }
        }
        return resultPackage
    }

This function is called after the engine is (successfully? at least it doesn't crash or throw any errors) initialized and an editor incl. renderer is associated with it. It's called with "New" as the package name.

        do {
            if let package = try createPackage(packageName: "New") {
                try editor.part = package.getPartAt(0)
            }
        } catch {
            print("Error while creating package : " + error.localizedDescription)
        }

The log is (this is on a real device):

2018-05-11 15:17:23.448666+0200 ***REDACTED***[2079:991193] Error, -[IINKEngine createPackage:error:]::108 io error
(lldb) po fullPath
"file:///var/mobile/Containers/Data/Application/D2009107-3E65-4884-B92D-1F6A6ADF3262/Documents/New.iink"

(lldb) po fullPath.decomposedStringWithCanonicalMapping
"file:///var/mobile/Containers/Data/Application/D2009107-3E65-4884-B92D-1F6A6ADF3262/Documents/New.iink"

(lldb) 

When I add the following code and download the container I can see the file is being created:

try! Data(bytes: [1,2,3,4,5,6,7,8,9]).write(to: urlWithExtension)

image

Any help is appreciated!

Hi,


The issue comes with your fullPath value starting with "file://", which iink SDK does not know how to interpret as a valid URL. If I do a quick hack like the following one, it seems to work:

let fullPath = urlWithExtension.absoluteString.replacingOccurrences(of: "file://", with: "")

I hope that this will help!

Best regards,

Thomas


1 person likes this

Hey Thomas, thank you very much, that did it :) It would be great if iink would expect an (NS)URL and do the magic it needs internally though.

Login or Signup to post a comment