gpt4 book ai didi

ios - 如何使用 RCT_EXPORT_MODULE React Native

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:08 25 4
gpt4 key购买 nike

谁能解释一下如何使用 React Native 中的宏 RCT_EXPORT_MODULE 来创建具有非类名的特定名称的自定义 React 模块?

documentation说,

This takes an optional argument that specifies the name that the module will be accessible as in your JavaScript code

我的类(class)名字是:

@implementation ReactCustomService

但我想将其重命名为:

RCT_EXPORT_MODULE(@"CustomService")

但这行不通。当我这样做时:

var service = NativeModules.CustomService;

什么都没有返回。但如果我执行了 RCT_EXPORT_MODULE(),那么 NativeModules.ReactCustomService 就可以正常工作。

有什么想法吗?我还尝试了 RCT_EXPORT_MODULE("CustomService"),但这也不起作用。

我在 react-native: 0.40.0

最佳答案

传递名称时不带任何引号,例如。

RCT_EXPORT_MODULE(CustomService)

应该可行

关于ios - 如何使用 RCT_EXPORT_MODULE React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42824932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com