Interactive Ink

iOS SDK integration problems

Integrated iOS IinkSDK, the SDK integrated into my own Controller, initialize the 'editor' error, can not find the cause of the problem, the code is as follows:

image

image

image

image

image



Dear Harry,

currently, we do not have your code.

Do you also have an error message?

Best regards,

Olivier

 My code is the basic initialization operation, first verify the certificate, and then initialize the 'engine' and 'editor', the implementation of the following function error, "[self.editor setPart: [package getPartAt: 0 error: nil]];"
The following screenshot is an error message,

image

image


Dear Harry,

we are facing difficulties understanding what is wrong in your code.

Why are you doing self.engine  = self.engine?

Best regards,

Olivier

 


Below is our integration code

 

 

#import "AppDelegate.h"

- (IINKEngine *)engine
{
    if (!_engine)
    {
        // Check that the MyScript certificate is present
        if (myCertificate.length == 0)
        {
            self.engineErrorMessage = @"Please replace the content of MyCertificate.c with the certificate you received from the developer portal";
            return nil;
        }
        
        // Create the iink runtime environment
        NSData* certificateData = [NSData dataWithBytes:myCertificate.bytes length:myCertificate.length];
        self.engine = [[IINKEngine alloc] initWithCertificate:certificateData];
        if (self.engine == nil)
        {
            self.engineErrorMessage = @"Invalid certificate";
            return nil;
        }
        
        // Configure the iink runtime environment
        NSString *configurationPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"recognition-assets/conf"];
        [self.engine.configuration setStringArray:@"configuration-manager.search-path" value:@[configurationPath] error:nil]; // Tells the engine where to load the recognition assets from.
        
        // Set the temporary directory
        [self.engine.configuration setString:@"content-package.temp-folder" value:NSTemporaryDirectory() error:nil];
    }
    return _engine;
}

 

- (IINKEngine *)engine
{
    if (!_engine)
    {
        // Check that the MyScript certificate is present
        if (myCertificate.length == 0)
        {
            self.engineErrorMessage = @"Please replace the content of MyCertificate.c with the certificate you received from the developer portal";
            return nil;
        }
        
        // Create the iink runtime environment
        NSData* certificateData = [NSData dataWithBytes:myCertificate.bytes length:myCertificate.length];
        self.engine = [[IINKEngine alloc] initWithCertificate:certificateData];
        if (self.engine == nil)
        {
            self.engineErrorMessage = @"Invalid certificate";
            return nil;
        }
        
        // Configure the iink runtime environment
        NSString *configurationPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"recognition-assets/conf"];
        [self.engine.configuration setStringArray:@"configuration-manager.search-path" value:@[configurationPath] error:nil]; // Tells the engine where to load the recognition assets from.
        
        // Set the temporary directory
        [self.engine.configuration setString:@"content-package.temp-folder" value:NSTemporaryDirectory() error:nil];
    }
    return _engine;
}

 

 

#import "TestViewController.h"
#import "IInkUIReferenceImplementation.h"
#import <iink/IINK.h>
#import "NSFileManager+Additions.h"
#import "AppDelegate.h"

@interface TestViewController ()<IINKIRenderTarget>

@property (strong, nonatomic) IINKEngine *engine;

@property (strong, nonatomic) IINKEditor *editor;

@property (strong, nonatomic) FontMetricsProvider *fontMetricsProvider;

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
    
    if (![self checkEngine])
        return;
    
    self.engine = self.engine;
    
    [self initEditor];
    
    IINKContentPackage *package = [self createPackageWithName:@"NewPackage"];
    
    NSError *error = nil;
    
    [package getPartAt:0 error:&error];
    
    if (error) {
        NSLog(@"move failed:%@", [error localizedDescription]);
    }
    
    [self.editor setPart:[package getPartAt:0 error:&error]];
    
    

}

#pragma mark - Engine

- (BOOL)checkEngine
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if (appDelegate.engine != nil)
        return YES;
    
    NSString *message = appDelegate.engineErrorMessage;
    UIAlertController *errorController = [UIAlertController alertControllerWithTitle:@"Certificate Error"
                                                                             message:message
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {
                                                         exit(1);
                                                     }];
    [errorController addAction:okAction];
    [self presentViewController:errorController animated:YES completion:nil];
    return NO;
}

- (IINKEngine *)engine
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    return appDelegate.engine;
}

- (void)initEditor
{
    ImageLoader *imageLoader = [[ImageLoader alloc] init];
    imageLoader.cacheFolderPath = [[NSFileManager defaultManager] tmpDirectory];
    
    IINKRenderer *renderer = [self.engine createRendererWithDpiX:scaledDpi() dpiY:scaledDpi() target:self];
    
    self.editor = [self.engine createEditor:renderer];
    [self.editor setViewSize:self.view.bounds.size];
    self.fontMetricsProvider = [[FontMetricsProvider alloc] init];
    [self.editor setFontMetricsProvider:self.fontMetricsProvider];
    imageLoader.editor = self.editor;
    
    //    self.displayViewController.renderer = renderer;
    //    self.displayViewController.imageLoader = imageLoader;
    //    self.inputView.editor = self.editor;
}

- (IINKContentPackage *)createPackageWithName:(NSString *)name
{
    // Create a new content package with name
    NSString *fullPath = [[[NSFileManager defaultManager] pathForFileInDocumentDirectory:name] stringByAppendingPathExtension:@"iink"];
    IINKEngine *engine = ((AppDelegate *)[UIApplication sharedApplication].delegate).engine;
    IINKContentPackage *package = [engine createPackage:fullPath.decomposedStringWithCanonicalMapping error:nil];
    
    // Add a blank page type Text Document
    IINKContentPart *part = [package createPart:@"Text" error:nil]; // Options are : "Diagram", "Drawing", "Math", "Text Document", "Text"
    
    self.title = [NSString stringWithFormat:@"Type: %@", part.type];
    return package;
}



@end

 

image


Dear Harry,

referring to the error raised, the invalidate function has not been implemented...

You should ensure to implement the IINKIRenderTarget protocol.

Best regards,

Olivier
Dear Harry,

Please note we provide an implementation of IINKIRenderTarget inside the UI Reference implementation. You can then use it as a reference.

Best regards,

Olivier

Can get the recognition result, thank you very much