iink SDK on Device

Answered

Where does the code need to go?

Hi,

I'm relatively new to IOS development, but I've now got a project in which I would like to use iink to recognise written input from a user, turn it into text and then store that in a database.

I've downloaded the getting started example and got that compiling and running, and now I'm trying to work my way through the example calculator app. I've got the pod installed and all appears to be good with that (which is more than I managed when I last played with this!), and I've downloaded the appropriate language files and put those in my project along with the certificate I've generated for the project.

I'm using the main storyboard in the XCODE project, and it links to a file called inkyStories.swift.  

Reading the sample app, I believe that the following code needs to be used to instantiate and configure the iink engine:

@property (strong, nonatomic) IINKEngine *engine; - (void)viewDidLoad { [super viewDidLoad]; // Create the engine NSData *certificateData = [NSData dataWithBytes:myCertificate.bytes length:myCertificate.length]; self.engine = [[IINKEngine alloc] initWithCertificate:certificateData]; // Get the configuration object IINKConfiguration *configuration = self.engine.configuration; // Set the recognition resources path NSString *configurationPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"recognition-assets/conf"]; [configuration setStringArray:@[ configurationPath ] forKey:@"configuration-manager.search-path" error:nil]; // Set the temporary directory [configuration setString:NSTemporaryDirectory() forKey:@"content-package.temp-folder" error:nil]; // Set the math fractional part precision [configuration setNumber:2 forKey:@"math.solver.fractional-part-digits" error:nil]; }

However, being a complete newbie, I'm not sure where this code needs to go and in what file. Does it go in the UIViewController class for my main.storyboard, do I need to make a new class completely, or does it have to go in a separate file even? Wherever I put it at the moment, I'm getting lots of errors, so I suspect I'm missing something major. The code below is where I'd expected to put it:

import Foundation

import UIKit


class inkyStoriesUIViewController {

    @property (strong, nonatomic) IINKEngine *engine;

    

    override func viewDidLoad() {

        

    print ("Loading View Controller, please show me something?")

     

        {

          [super viewDidLoad];


          // Create the engine

          NSData *certificateData = [NSData dataWithBytes:myCertificate.bytes length:myCertificate.length];

          self.engine = [[IINKEngine alloc] initWithCertificate:certificateData];


          // Get the configuration object

          IINKConfiguration *configuration = self.engine.configuration;


          // Set the recognition resources path

          NSString *configurationPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"recognition-assets/conf"];

          [configuration setStringArray:@[ configurationPath ] forKey:@"configuration-manager.search-path" error:nil];

          

          // Set the temporary directory

          [configuration setString:NSTemporaryDirectory() forKey:@"content-package.temp-folder" error:nil];


          // Set the math fractional part precision

          [configuration setNumber:2 forKey:@"math.solver.fractional-part-digits" error:nil];

        }

    

    }


}


image





Best Answer

Dear Robert,


after git clone of the interactive-ink-examples-ios, the getStarted swift sample can be found into the  "Examples/GetStartedSwift" repositoy: https://developer.myscript.com/docs/interactive-ink/1.3/ios/fundamentals/get-started/#playing-with-the-get-started-example


Best regards,


Olivier


Dear Robert,


thank you for the interest you show to our technology.


The questions you raised are not directly related to our technology but are "basic" Objective C questions. We recommend you refer to Objective C tutorials, which you can find on the internet. You should then be able to solve the below points.


Best regards,


Olivier

Hang on, your example application is ObjectiveC not swift? That’s probably where I’m going wrong... Are there any examples of swift usage? Or would I be better putting that code in a C header and import it using my bridging header file?
Answer

Dear Robert,


after git clone of the interactive-ink-examples-ios, the getStarted swift sample can be found into the  "Examples/GetStartedSwift" repositoy: https://developer.myscript.com/docs/interactive-ink/1.3/ios/fundamentals/get-started/#playing-with-the-get-started-example


Best regards,


Olivier