【发布时间】:2020-11-10 13:54:44
【问题描述】:
网址:https://github.com/cocos-creator/creator-docs/blob/master/en/advanced-topics/oc-reflection.md
以上是Cocos脚本调用Objective-C方法的文档
我试图做完全相同的事情,但我得到了错误
2020-07-21 15:56:01.094441+0800 hello_world-mobile[63684:4206926] TestingLogging.testingIntegration method isn't found!
[ERROR] (/Applications/CocosCreator/Creator/2.3.3/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm, 418): call (TestingLogging.testingIntegration) failed, result code: -3
[ERROR] Failed to invoke JavaScriptObjCBridge_callStaticMethod, location: /Applications/CocosCreator/Creator/2.3.3/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/manual/JavaScriptObjCBridge.mm:427
.h 类
//
// TestingLogging.h
// hello_world-mobile
//
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TestingLogging : NSObject
+(void) testingIntegration: (NSString *) string;
@end
NS_ASSUME_NONNULL_END
.m 类
//
// TestingLogging.m
// hello_world-mobile
//
//
#import "TestingLogging.h"
@implementation TestingLogging
+(void)testingIntegration:(NSString *)string {
NSLog(@"First ios call from cocos creator app %@", string);
}
@end
cocos 中的脚本
onCameraClickHandler () {
if(cc.sys.OS_IOS == cc.sys.os) {
var ret = jsb.reflection.callStaticMethod("TestingLogging", "testingIntegration", "Hello iOS")
}
}
你能帮帮我吗!
【问题讨论】:
标签: javascript objective-c cocos2d-js