Titanium iOS模块运行时错误

时间:2015-06-24 21:37:17

标签: ios titanium appcelerator-mobile titanium-modules

我正在尝试创建一个导入自定义文件的简单iOS模块。

我的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

这就是我在AppcCalcModule.m

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

编译模块一切正常:BUILD SUCCEEDED

当我在Titanium中导入它并在index.js中调用它时

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

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

崩溃并发出以下错误:

[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)

如果我在没有以下行的情况下编译模块:

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

一切顺利,应用程序运行完美。

我想要成功的是:当我调用模块的函数示例时,可以执行以下代码:

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]];

如果您想尝试,我在github上发布了源代码:ios applicationios module

任何人都可以解释为什么会发生这种情况!

谢谢!

0 个答案:

没有答案