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

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?

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

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>

If you close the app on the device (so that XCode shows it as stopped) and then start the app again (through the device, not with XCode), the console logs will go to the terminal (assuming metro is running).
Of course, you don't get XCode debug logs, for my needs that's fine.

Related

Xcode 14 is not getting attached to Simulator in Debug mode

While debugging any iOS application, Xcode builds and run successfully, also launches a simulator but it is not able to attach debugger from Xcode 14 to Simulator iOS app.
It throws an error in Xcode:
Xcode console says:
Could not attach to pid : “75997” Domain: IDEDebugSessionErrorDomain
Code: 3 Failure Reason: attach failed (Not allowed to attach to
process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.) User Info: {
DVTRadarComponentKey = 855031;
IDERunOperationFailingWorker = DBGLLDBLauncher;
RawUnderlyingErrorMessage = "attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.)"; }
Tried with re-installing Xcode and Command line tools, but issue persists.
Steps:
Build and run app with Debug executables true
Simulator gets launched
Error on Xcode and it gets disconnected from simulator
Is there a possibility that it can be blocked by any other app, if so how to identify ?
I solved the issue by doing the steps below:
SOLUTION 1:
Edit the scheme
Select Run
Select Build Configuration "Debug"
Select "Wait for the executable to be launched"
Close
Run the app
see the screenshot here
You will receive an error message when you run the app again.
Close the app.
Edit the scheme again and change "Wait for the executable to be launched" to "Automatically".
Now your simulator will work as expected.
SOLUTION 2:
Delete your app folder in Derived Data
/Users/[your username]/Library/Developer/Xcode/DerivedData/
Search your app name folders and delete them.
SOLUTION 3:
Open the terminal and run:
sudo DevToolsSecurity -enable
This command enables the Developer Mode. After running the command you will receive this message: [Developer mode is now enabled].
Sometimes it's happen, when you are trying to build too fast after a build has started.
First of all, quit your current simulator, delete derived data and clean the project, wait until whole processing is complete. Then do some changes / editing if required (as we clean all data) and try running on a different simulator.
Check certificates in key-chain access, if you found any untrusted certificates in key-chain access remove it.
Also if you are using beta version just make sure it is downloaded from Apple official website.
Came here to share my (strange) solution if anybody crosses the same problem with no answers working. In my case, no solution from this nor other SO answers to similar questions worked (cleaning, rebuilding project, updating, clearing derived data..)
My setup is:
Macbook M1 2022 + Xcode Version 14.2 (14C18)
This Xcode version could not attach to any of my apps (fresh new or previously developed) on different simulators (11, 12, 14) with iOS versions 13.7 - 16.2.
Editing scheme solution from answer above was not working also so I ended up in leaving scheme as:
Build configuration: Release
Debug executable Deselected(!)
Launch Automatically
And magically debugging app in Xcode started working even though it's release version with debug option deselected.. Selecting Debug executable again makes Xcode not possible in attaching to app process
Just to clarify: above steps actually makes app to run as in DEBUG mode - Xcode attaches to pid, I can do console logs and breakpoints. This Xcode version behaves opposite than options selected

Xcode running iOS app without updated code. Ionic live reload not working

ionic cordova emulate ios -l <target>
Does not work for me. I get an error suggesting that I am targeting the wrong device even though the device I am targeting is listed as a virtual device when running the command:
ionic cordova emulate --list
When I run the app with Xcode instead it works however it does not reload my edits, even if I stop and start the app again.
*** disclaimer: this is both a quick and dirty solution to the aforementioned issues ***
Before running your app in Xcode (pressing the play button), in your project directory run the following command:
ionic cordova prepare ios
This will load your changes and update your app in Xcode before running it in your emulator so you can then debug and see your edits.
Open to suggestions if anyone has a more direct solution!
Try:
cleaning the build folder in Xcode: cmd+shift+k
In the "Device" menu of Simulator, click "Erase All Content and Settings"
Quit Xcode, simulator and whatever program you are running the emulate command in
Reboot the machine

ionic cordova run ios - nothing happens

I'm trying to deploy my Ionic app to an iPhone by running either of these commands:
ionic cordova run ios
ionic cordova run ios --device
The console displays the following text:
[OK] Your app has been deployed.
Did you know you can live-reload changes from your app with --livereload?
If we look at the console output everything seems to be fine, but my iPhone doesn't detect anything and the application doesn't run. I managed to get it on my phone by opening the workspace file inside the platforms/ios and running it with Xcode, but that's a pretty tedious process, and I'm sure that's not the way to go, as it doesn't support livereload.
Also, I tried to start a new project and I'm having the same issue, so I guess it's not any plugin's fault.
Thanks in advance for your answers.
When you run the app from Xcode, does Xcode give you any more error messages in its output window? This may be a signing issue.
same error here from console.
with --verbose
get this message
registerShutdownFunction.process.exit/normal shutdown

React Native app not running in XCode iOS simulator

I try to make my first steps using React Native. Development for Android (on Windows host) works. Now I wanted to test iOS, and tried to set up a development environment on a MacBook Pro.
Problem: React Native starts the iOS simulator, and then nothing happens any more. The simulator runs OK, but my React native app won't start.
What do I need to do to get my React Native installation going?
More Info:
I set up XCode and React Native according to the docs on the MacBook Pro running OSx 10.13.2 (High Sierra). XCode was installed and tested successfully, including the simulator.
When I installed Node.js I deliberately picked an older version (containing npm 4.2.0), since forums say that React Native does still have problems with npm 5. I also installed Homebrew and Watchman, like stated in the docs.
To initialize an empty project, I used
create-react-native-app HelloWorldProject
and a projet structure got created in my Documents folder.
If I finally fire up my "Hello World" test app using
cd HelloWorldProject
sudo react-native run-ios
the system responds:
Starting packager ...
Starting simulator ...
and then nothing happens. The simulator does indeed start (boot --> apple logo --> progress bar --> IOs start screen), but nothing happens afterwards.
Edit
I have given up on React Native for several reasons, I leave this question here for documentary purposes, but I cannot verify or accept any answer, I don't have a React Native development environment any more.
It's probably because you used sudo. /.expo/ is owned by root. Try to change the ownership with
sudo chown -R `whoami` ~/.expo
Refer https://github.com/react-community/create-react-native-app/issues/422
Even everything in your app seems fine, sometime you face the issue that the app is taking too much time to load either through terminal or Xcode. If there is no any other specific issue with your project, the following solution works most of the time:
Go to your app folder and then go to 'iOS' folder.
Delete 'Podfile.lock' and 'Pods' folder.
Execute the following command in Terminal from your 'ios' folder, that will bring back the 'Podfile.lock' and required Pods will be installed to 'Pods' folder:
pod install
Delete the 'build' folder in your 'iOS' folder.
Run the following command in terminal:
react-native run-ios
While the terminal is running, open '.xcworkspace' in your 'ios' folder in Xcode.
The above steps will make sure it will be build your react native project newly and will run on the simulator.
Thanks
Wasantha Wijayaratna

iOS emulator no longer running from command line using phonegap

My iOS emulator is no longer opening when I run "phonegap run ios" in the terminal on Mac OS X. I receive no error messages and:
[phonegap] Platform "ios" deployed to emulator.
[phonegap] successfully installed onto emulator
While this is currently a known bug, you can run the emulate command more directly (note you need to build separately):
phonegap local build ios
/platforms/ios/cordova/emulate
You can also run the application using the same technique:
phonegap local build ios
/platforms/ios/cordova/run
NOTE: When using this method to run the app on your phone, the task might get stuck on the splash screen. To fix this, launch the Activity Monitor on your Mac and quit any processes with the name "ios-deploy". From there you can launch the application on your phone by clicking the application icon.
Or, you can even look inside the generated /platforms/ios folder and launch XCode project directly to test in an emulator or on your device. Open project and click the RUN button.
IMPORTANT: with all of the above methods, you MUST run the build command before running:
phonegap local build ios
Not really an answer, but I can say this is a known bug. Here is the bug so you can track it:
https://issues.apache.org/jira/browse/CB-5103
I only had this problem after upgrading to 3.1. I downgraded to 3.0 and it works more reliably:
npm uninstall -g phonegap
npm install -g phonegap#3.0
Also had to delete the platform/ios dir and plugins/ios.json and then run 'phonegap build ios' and 'phonegap run ios'

Resources