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
React Native: Can't see console.logs when I run application from XCode
提问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-ios
but 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.log
works. 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
cmd ? + Dto bring up the debug menu
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
--dev
flag:react-native bundle --dev
And
console.log
messages are back! If you aren't bundling for a real device, don't forget to re-pointjsCodeLocation
inAppDelegate.m
to localhost (I did!).
cmd ? + 调D出调试菜单
将“在 Safari 中调试”设置为关闭,一些消息将打印到输出消息,而不是控制台消息。但是,其中一条日志消息说:
DEV=== false,开发级警告关闭,性能优化开启”
这是因为我之前已经将我的项目捆绑在真实设备上使用以下命令进行测试:
react-native bundle --minify
这个捆绑没有“开发模式”。要允许开发消息,请包含以下
--dev
标志:反应原生包 --dev
而
console.log
消息回来了!如果不捆绑为一个真正的设备,不要忘了再点jsCodeLocation
在AppDelegate.m
本地主机(我做到了!)。
回答by Bap
It seems that react-native log-ios
is not working anymore since RN .50
You can use react-native-log-ios
npm package instead
react-native log-ios
从 RN .50 开始,它似乎不再起作用了,您可以改用react-native-log-ios
npm 包
npm i -g react-native-log-ios
and then
进而
react-native-log-ios <XCode Project Name>