ReactNative native-modules Promise 传递字段并在 Swift

ReactNative native-modules Promise passing field and in Swift

我正在尝试 运行 在 React Native 中使用 Swift 并传递一个字段(数组)的承诺。 这是我的代码:

GuidedTourInterfaceBridge.m

@interface RCT_EXTERN_MODULE(GuidedTourInterface, NSObject)

   RCT_EXTERN_METHOD(readFile(_ arr: NSArray, resolver: RCTPromiseResolveBlock resolve, rejecter reject: RCTPromiseRejectBlock reject))
@end

GuidedTourInterface.swift:

...
@objc
func readFile(_ arr: NSArray, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
    ...
    resolve(["success" : true, "base64Content" : base64Content ])
}
...

JS 文件:

...
readFileInfoJson = async () => {
  try {

      var result = await guidedTourInterface.readFile([this.props.mapToShow+"/info.json"]);
      ...
   } catch (e) {
      console.error(e);
   }
 }

我收到的错误消息:

guidedTourInterface.readFile is not a function. (In 'guidedTourInterface.readFile([_this.props.mapToShow+"/info.json"])', 'guidedTourInterface.readFile' is undefined)]

你对如何解决这个问题或我做错了什么有什么建议吗? 提前致谢

我想出了解决问题的方法。这是为可能需要的任何人提供的解决方案

GuidedTourInterfaceBridge.m

RCT_EXTERN_METHOD(readFile:(NSArray *)arr resolve:(RCTPromiseResolveBlock *)resolve reject:(RCTPromiseRejectBlock *)reject)

GuidedTourInterface.swift:

  func readFile(_ arr: NSArray, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {

JS 文件:

var result = await guidedTourInterface.readFile([this.props.mapToShow+"/info.json"])
          .then((result) => {