繁体   English   中英

查看本机应用程序的swift stdout

[英]See swift stdout for a react-native application

假设我有以下React Native代码:

import { NativeModules, Platform } from 'react-native'

if (Platform.OS === 'ios') {
  NativeModules.ExampleThing.exampleMethod('example')
}

以下Swift类:

@objc(ExampleThing)
class ExampleThing: NSObject {
  private override init() {
    print('init')
  }

  @objc func exampleMethod(_ message: String) -> Void {
    print(message)
    //do more complex thing
  }
}

和以下桥接头:

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

@interface RCT_EXTERN_MODULE(ExampleThing, NSObject)

RCT_EXTERN_METHOD(exampleMethod:(NSString *)message)
@end

当我运行react-native run-ios ,应用程序开始在模拟器就好了,例如:效果exampleMethod (发送消息到Segment.IO)时,ERGO exampleMethod是很清楚的得到正确调用。 但是,对于我来说,我找不到打印命令要打印到的位置。 我也尝试过os_log

您需要通过XCode而不是react-native run-ios运行项目,并且该项目将显示在XCode输出控制台上。

您还可以使用XCode的断点等代替print语句来帮助调试。

暂无
暂无

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

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