简体   繁体   English

Objective-c class 通过桥接暴露 header 从 Z818056DBD7E201248206B9CCD8

[英]Objective-c class exposed via bridging header not visible from swift when archiving release

In my react native project, I try to expose a swift function to the javascript code.在我的 react native 项目中,我尝试将 swift function 公开给 javascript 代码。 It works well in debug mode, but when trying to archiving I get a Use of undeclared type RCTEventEmitter error on my swift file.它在调试模式下运行良好,但在尝试归档时,我的 swift 文件出现Use of undeclared type RCTEventEmitter错误。

The RCTEventEmitter is imported in my RNUtils.m file, and in the bridging header. RCTEventEmitter被导入到我的RNUtils.m文件和桥接 header 中。

So I guess somewhere in the archiving, something fail with the bridging header, but I have no idea where.所以我猜在存档的某个地方,桥接 header 失败了,但我不知道在哪里。 If I ask for a non existing import, it will tell me that it can't compile the bridging header, so the file is taken into account during the build.如果我要求一个不存在的导入,它会告诉我它无法编译桥接 header,因此在构建过程中会考虑该文件。

// 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 react-native 0.61.5
  • xcode 11.5 xcode 11.5
  • Swift 5 Swift 5

It appears I needed to add ìmport React` in every swift file.看来我需要在每个 swift 文件中添加“导入反应”。 It's archiving fine now.现在存档就好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM