uni-app开发原生ios插件时,跟着教程操作报错

uni-app开发原生ios插件时,跟着教程操作报错

TypeError: undefined is not an object (evaluating 'r.testAsyncFunc') __ERROR  

![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211025/2d0b24144b081a3e096927dbb6840f89.png)
![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211025/803171e742054253b8cde7e1e3e1096d.png)
![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211025/6761352d6275ec4e70e886b9b62689b1.png)
![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211025/15bc8313615255ec67789e6f7fbd162c.png)
![Image](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211025/61da4a5f793928f07b3626bb72b08a9f.png)

更多关于uni-app开发原生ios插件时,跟着教程操作报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

原生插件相关问题可加群反馈 原生开发官方QQ交流群 群2:814228233 群3:455763866 群1:256775471

更多关于uni-app开发原生ios插件时,跟着教程操作报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我也遇到相同的问题了,我是直接使用SDK中的示例的,结果还是有这个问题,不知道怎么解决

这个错误表明在iOS原生插件中,testAsyncFunc方法没有被正确导出或调用。

从截图看,主要问题在于:

  1. 方法导出不匹配:在TestModule.m中,你通过UNI_EXPORT_METHOD宏导出了testAsyncFunc方法,但JavaScript调用的方法名可能不一致。

  2. 参数传递问题:异步方法需要正确接收UniModuleKeepAliveCallback回调参数。确保方法签名正确:

UNI_EXPORT_METHOD(@selector(testAsyncFunc:callback:))
  1. 插件配置检查

    • 确认TestModule已在UniPluginProtocol中注册
    • 检查module.json配置是否正确
    • 确保插件包被正确引入到Xcode工程
  2. 调用方式验证: JavaScript端应使用:

const testModule = uni.requireNativePlugin('TestModule')
testModule.testAsyncFunc(...)
回到顶部