1.声明一个oc的类, 写下方法
.h
@interface PlatformSystem : NSObject<UIAlertViewDelegate>
+ (void)noparams;
+ (void)oneparam:(NSString *)params;
+ (NSString *)twoparams:(NSString *)params andContent:(NSString *)params2;
@end
.mm
@implementation PlatformSystem
+ (void)noparams{
NSLog(@"TESTMETHOD===========0");
NSLog(@"TESTMETHOD===========0");
}
+ (void)oneparam:(NSString *)params{
NSLog(@"TESTMETHOD===========1");
NSLog(@"TESTMETHOD===========1");
}
+ (NSString *)twoparams:(NSString *)params andContent:(NSString *)params2{
NSLog(@"TESTMETHOD===========2");
NSLog(@"TESTMETHOD===========2");
return @"";
}
@end
2.cocos2d-js有封装了oc的调用代码
// 无参数
cc.game.callNative("PlatformSystem", "noparams");
// 一个参数
cc.game.callNative("PlatformSystem", "oneparam:", "");
// 二个参数
cc.game.callNative("PlatformSystem", "twoparams:andContent:", "", "");
cc.game.callNative = function(classname, methodname, args){
var ok, ret = jsb.reflection.callStaticMethod(classname, methodname, args);
cc.log("=====", ret);
};
_本站文章为 宝宝巴士 SD.Team 原创, 转载务必在明显处注明:(作者官方网站: 宝宝巴士 ) _
_转载自【宝宝巴士SuperDo团队】原文链接: http://www.jianshu.com/p/2b7bd88b13f3