React Native 模块找不到类型 RCTPromiseResolveBlock 不在范围内

发布于 2025-01-18 16:47:32 字数 1458 浏览 2 评论 0原文

我是在React Native中构建模块的新手,并且由于某种原因,我尝试使用React Native模块构建本机模块。我已经在线搜索了谷歌搜索,它说只需将导入添加到您的桥接文件中即可将Object-C代码曝光到Swift,但对我来说似乎并没有发生。不确定我是否错过了什么,还是我错过了什么。

cannot find type 'RCTPromiseRejectBlock' in scope
cannot find type 'RCTPromiseResolveBlock' in scope

我包括< react/rctbridgemodule.h>在我的appName-bridging-header.m文件中,但结果仍然相同,我删除了所有node_modules,podfile和podfile和rebuild uld uld and Repuild uss uss and code>。

# App-Bridging-Header.m
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <React/RCTConvert.h>
ModuleFile.m
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTConvert.h>

@interface RCT_EXTERN_MODULE(Vgas, NSObject)

RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
                 withResolver:(RCTPromiseResolveBlock)resolve
                 withRejecter:(RCTPromiseRejectBlock)reject)

@end

#swift file
import Foundation

@objc(Vgas)
class Vgas: NSObject {

    @objc(multiply:withB:withResolver:withRejecter:)
    func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
        resolve(a*b)
    }
}

I am new to building modules in react native and trying to build a native module with react native module, for some reason I get. I have googled online and it says just add the imports to your bridging file to expose object-c code to swift but seems its not happening for me. not sure if i missed something or i am missing something.

cannot find type 'RCTPromiseRejectBlock' in scope
cannot find type 'RCTPromiseResolveBlock' in scope

I included <React/RCTBridgeModule.h> in my AppName-Bridging-Header.m file but still same result, i have removed all node_modules, podfile and rebuild and still same problem.

# App-Bridging-Header.m
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <React/RCTConvert.h>
ModuleFile.m
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTConvert.h>

@interface RCT_EXTERN_MODULE(Vgas, NSObject)

RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
                 withResolver:(RCTPromiseResolveBlock)resolve
                 withRejecter:(RCTPromiseRejectBlock)reject)

@end

#swift file
import Foundation

@objc(Vgas)
class Vgas: NSObject {

    @objc(multiply:withB:withResolver:withRejecter:)
    func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
        resolve(a*b)
    }
}

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文