React Native 模块找不到类型 RCTPromiseResolveBlock 不在范围内
我是在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)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论