Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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.

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

like image 849
wheresmycookie Avatar asked Oct 13 '16 20:10

wheresmycookie


2 Answers

Option #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.

Option #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 log-ios
react-native log-android

Option #3

  1. cmd ⌘ + D to 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 --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-point jsCodeLocation in AppDelegate.m to localhost (I did!).

like image 173
Annie Gupta Avatar answered Oct 18 '22 23:10

Annie Gupta


It seems that react-native log-ios is not working anymore since RN .50 You can use react-native-log-ios npm package instead

npm i -g react-native-log-ios

and then

react-native-log-ios <XCode Project Name>
like image 12
anni Avatar answered Oct 18 '22 23:10

anni