我对 React 有一些经验,但我是 React Native 的新手。我已经玩了一段时间,但是当我尝试为 iOS 编写一个基本的本机模块时,我被卡住了。我已经尝试过 Swift 和 Objective C。(我对 Swift 有一些基本的经验,但 Objective C 对我来说是全新的)
一些背景:
react-native-cli 2.0.1XCode 9.1这是 .swift 类
import Foundation
@objc(Something)
class Something: NSObject {
@objc
func printSomething() -> Void {
print("Something")
}
}
Run Code Online (Sandbox Code Playgroud)
这是桥文件
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(Something, NSObject)
RCT_EXTERN_METHOD(printSomething)
@end
Run Code Online (Sandbox Code Playgroud)
和 Project-Brigding-Header.h
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <React/RCTBridgeModule.h>
Run Code Online (Sandbox Code Playgroud)
我的 App.js 文件 …