URL : https://github.com/cocos-creator/creator-docs/blob/master/en/advanced-topics/oc-reflection.md
Above is the documentation to call a Objective-C method from Cocos script
I trying to do the exact same thing, but I get the error
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 class
//
// 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 class
//
// TestingLogging.m
// hello_world-mobile
//
//
#import "TestingLogging.h"
@implementation TestingLogging
+(void)testingIntegration:(NSString *)string {
NSLog(@"First ios call from cocos creator app %@", string);
}
@end
Script in cocos
onCameraClickHandler () {
if(cc.sys.OS_IOS == cc.sys.os) {
var ret = jsb.reflection.callStaticMethod("TestingLogging", "testingIntegration", "Hello iOS")
}
}
Could you please help me !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…