提问者:小点点

Objective-c类通过桥接报头公开,在存档发行版时,swift中不可见


在我的react原生项目中,我尝试向javascript代码公开一个swift函数。 它在调试模式下运行良好,但在尝试存档时,我在swift文件上遇到了使用未声明类型RCTEventemitter错误。

RCTEventemitter导入到我的rnutils.m文件和桥接头中。

所以我猜在归档的某个地方,桥接报头出现了故障,但我不知道在哪里。 如果我要求一个不存在的导入,它会告诉我它无法编译桥接头,因此在构建过程中会考虑该文件。

// Utils.m
#import "React/RCTBridgeModule.h"
#import "React/RCTConvert.h"
#import "React/RCTEventEmitter.h"

@interface RCT_EXTERN_REMAP_MODULE(RNUtils, RNUtils, RCTEventEmitter)

@end

// Utils.swift
import Foundation

@objc(RNUtils)
class RNUtils: RCTEventEmitter {
  // my native code emitting events
}
// MyApp-Bridging-header.h
#ifndef MyApp_Bridging_Header_h
#define MyApp_Bridging_Header_h

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

#endif
  • React-Native 0.61.5
  • Xcode 11.5
  • Swift 5

共1个答案

匿名用户

似乎我需要在每个swift文件中添加“§mport react”。 现在存档很好。