Titanium iOS module runtime error

205 views Asked by At

I'm trying to create a simple iOS module that imports a custom file.h

My test.h

#import <Foundation/Foundation.h>

@interface Calci : NSObject {
   int number1;
   int number2;
}

-(void) setNumber1: (int) n1;
-(void) setNumber2: (int) n2;
-(int) addition;

@end

Test.m

#import "Test.h"

@implementation Calci

-(void) setNumber1:(int) n1 {
    number1 = n1;
}
-(void) setNumber2:(int) n2 {
    number2 = n2;
}
-(int) addition {
    return number1+number2;
}

@end

This is how I use it in AppcCalcModule.m

#import "Test.h"
...
-(void)startup { 
     [super startup];
     NSLog(@"[INFO] %@ loaded",self);
     Calci *calci = [[Calci alloc] init];
 }

Compiling the module goes all ok : BUILD SUCCEEDED

When I import it in Titanium and call it in index.js

var calc = require("appc.calc");

function doClick(e) {
   alert(calc.example());
}

it crashes and gives the following error:

[ERROR] :  ** BUILD FAILED **
[ERROR] :  The following build commands failed:
[ERROR] :   Ld build/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/x86_64/Test normal x86_64
[ERROR] :  (1 failure)
TRACE  | titanium exited with exit code 1
ERROR  | Error: ti run exited with error code 1
at ChildProcess.<anonymous>       (/Users/user/.appcelerator/install/4.0.2/package/node_modules/appc-cli-titanium/plugins/run.js:84:66)
at ChildProcess.emit (events.js:98:17)
at Process.ChildProcess._handle.onexit (child_process.js:820:12)

If I compile the module without the following line:

Calci *calci = [[Calci alloc] init];

everything goes ok, and the app runs perfectly.

What I want to succeed is: when I call the function example of the module, the following code can be exacuted:

Calci *calculator;
calculator = [Calci alloc];
calculator = [calculator init];
[calculator setNumber1: 35];
[calculator setNumber2: 65];

NSLog(@"Addition of two numbers %i", [calculator addition]);
return [NSString stringWithFormat:@"Addition of two numbers %i", [calculator addition]];

I published the source code on github: ios application and ios module if you want to try.

Can anyone explain why does this happen!

Thank you!

0

There are 0 answers