JSPatch icon indicating copy to clipboard operation
JSPatch copied to clipboard

JPC不起作用,找不到调用的C方法

Open fjp007 opened this issue 9 years ago • 5 comments

断点走到 void* functionPtr = dlsym(RTLD_DEFAULT, [funcName UTF8String]); if (!functionPtr) { return nil; } 就直接返回了

fjp007 avatar Oct 12 '16 09:10 fjp007

你这个是调用自己定义的函数吧?自己定义的函数如果编译的时候将符号stripped了是会找不到的

xiaochaoren avatar Oct 13 '16 06:10 xiaochaoren

自定义的函数也是找得到的,上完整代码看看?

bang590 avatar Oct 13 '16 06:10 bang590

貌似是作用域的问题。require('JPEngine').addExtensions(['JPCFunction']);写在了defineclass外就是这个结果。 现在改成: defineClass('JPViewController', { handleBtn: function(sender) { var tableViewCtrl = JPTableViewController.alloc().init() self.navigationController().pushViewController_animated(tableViewCtrl, YES) self.passStruct({a:1, b:2})

require('JPEngine').addExtensions(['JPCFunction']);
defineCFunction("cfunctionWithId", "id, NSString *")
var ret = cfunctionWithId("JSPatch");
console.log(ret.toJS());

} }) 正常运行了。

fjp007 avatar Oct 14 '16 04:10 fjp007

写在defineClass外应该也是有效的

bang590 avatar Oct 14 '16 05:10 bang590

JSPatch-master.zip

你好,完整测试代码在demo->iOSDemo->JSPatchDemo里面,我在APPDelegate 定义了一个函数,在demo.js(第45行)进行调用,如果注释掉JPViewController 第21行调用不成功,去掉注释则调用成功 。不知道为什么会这样?

wangxinIOS avatar Feb 07 '17 03:02 wangxinIOS