React Native:当我从 XCode 运行应用程序时看不到 console.logs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40030709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:27:30  来源:igfitidea点击:

React Native: Can't see console.logs when I run application from XCode

iosxcodereact-native

提问by wheresmycookie

I'm struggling to get my code working with react-native run-ios. The native code is pulling some old cached version of the javascript bundle, and I can't seem to clear that to save my life.

我正在努力让我的代码与react-native run-ios. 本机代码正在提取一些旧的缓存版本的 javascript 包,我似乎无法清除它以挽救我的生命。

When I run the application from XCode however, the application runs just fine. Awesome!

但是,当我从 XCode 运行该应用程序时,该应用程序运行得很好。惊人的!

The only problem is that when I run my application through XCode, I can't seem to access the javascript logs. I've tried react-native log-iosbut that doesn't seem to show my logs. I've tried "Enabling debugging in Chrome" from the simulator menu, but this option isn't available to me when I run the app from XCode.

唯一的问题是,当我通过 XCode 运行我的应用程序时,我似乎无法访问 javascript 日志。我试过了,react-native log-ios但这似乎没有显示我的日志。我已经尝试从模拟器菜单中“在 Chrome 中启用调试”,但是当我从 XCode 运行应用程序时,这个选项对我不可用。

Does anybody have any thoughts on what might be going on here?

有没有人对这里可能发生的事情有任何想法?

采纳答案by Annie Gupta

Option #1

选项1

console.logworks. By default on iOS, it logs to the debug pane inside Xcode. If you select the "Debug in Chrome" or "Debug in Safari" options from the rage shake menu (?+^+Z), it will log to the browser's console instead.

console.log作品。默认情况下,在 iOS 上,它会记录到 Xcode 内的调试窗格。如果您从 rageshake 菜单中选择“在 Chrome 中调试”或“在 Safari 中调试”选项(?+^+Z),它将改为登录到浏览器的控制台。

Option #2

选项#2

As of React Native 0.29 you'll be able to simply run the following to see logs on the command line:

从 React Native 0.29 开始,您将能够简单地运行以下命令来查看命令行上的日志:

react-native log-ios
react-native log-android

Option #3

选项#3

  1. cmd ? + Dto bring up the debug menu

  2. Set "Debug in Safari" turned off, and some messages would be printed to the output message, but not console messages. However, one of the log message says:

    DEV=== false, development-level warning are OFF, performance optimizations are ON"

    This was because I had previously bundled my project for testing on a real device with the command:

    react-native bundle --minify
    

    This bundled without "dev-mode" on. To allow dev messages, include the --devflag:

    react-native bundle --dev

    And console.logmessages are back! If you aren't bundling for a real device, don't forget to re-point jsCodeLocationin AppDelegate.mto localhost (I did!).

  1. cmd ? + 调D出调试菜单

  2. 将“在 Safari 中调试”设置为关闭,一些消息将打印到输出消息,而不是控制台消息。但是,其中一条日志消息说:

    DEV=== false,开发级警告关闭,性能优化开启”

    这是因为我之前已经将我的项目捆绑在真实设备上使用以下命令进行测试:

    react-native bundle --minify
    

    这个捆绑没有“开发模式”。要允许开发消息,请包含以下--dev标志:

    反应原生包 --dev

    console.log消息回来了!如果不捆绑为一个真正的设备,不要忘了再点jsCodeLocationAppDelegate.m本地主机(我做到了!)。

回答by Bap

It seems that react-native log-iosis not working anymore since RN .50 You can use react-native-log-iosnpm package instead

react-native log-ios从 RN .50 开始,它似乎不再起作用了,您可以改用react-native-log-iosnpm 包

npm i -g react-native-log-ios

and then

进而

react-native-log-ios <XCode Project Name>