Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 985 of the free egghead.io lessons, plus get React content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

React Native: Debugging on an iOS Device

4:15 React lesson by

In this lesson we'll explore debugging our React Native application in an actual iOS device.


egghead.io comment guidelines

Avatar
egghead.io

In this lesson we'll explore debugging our React Native application in an actual iOS device.

Avatar
Scott

I think it's changed since - how do I debug on an iOS device as of 0.32? (not sure which version changed jsCodeLocation)

Once you've gone through the process of provisioning your application and identifying your device in the Apple developer program, rather than rendering to an emulator, we're going to render to our actual device. In order to do that, you're going to need to hardwire your device to your machine.

Now we're going to go ahead and try to play, or run, our application. It's actually not going to work, but we're going to give it a shot anyways. We can see the application has been added to our device. However, once it loads up we're going to get this error message, "Could not connect to development server."

To solve that we're going to jump to our "AppDelegate.m" file, and we're going to replace "localhost" with our machine's IP address. We're going to go ahead and save that, and we're going to stop and restart our application. Now we've got our actual application we can jump through the tabs. Everything is working.

Once we've got this on our actual device, what we can do to access the "developer menu" is pick it up, give it a shake, and the "developer menu" appears. I'm going to go ahead and enable "live reload." If we jump back over here to our code, we'll go ahead and make this tab "one," save it, and we can see it reloads on our actual device.

Another thing we can try is to load up "debug" in Chrome. However, we are going to hit another error. In order to solve this new error we're going to jump into our "node modules," into "react-native," into its "libraries" directory, and then finally into "WebSocket" and "RCTWebSocket." Here we're going to get the "RCTWebSocketExecutor.m."

Again, we're going to change "localhost" to our machine's IP address. We're going to go ahead and stop our application, and reload it. Now, as soon as we reloaded it, we got our Chrome debugging enabled. So we'll go ahead and load up the debugger, or the "dev tools," sorry. Jump over to our "react" tab, and we can see, you're going to have to drill down a little bit.

Here's our tab app, and we can see its selected tab, or its state of selected tab, is tab "one." If I go ahead and jump to tab "two," and then in our debugger reload that, we can see that our selected tab is "two." If I jump to tab "three," we can reload that and see it is in fact tab "three."

If we jump back to our "index.ios.js" and here in our "render method" becomes a "log-out rendering," we can see here in our console we have "rendering" each time we jump to a new tab. As we move towards production, we're going to want to decouple our code from this local host.

There's a handful of instructions here, but we want to uncomment line 46, and we want to copy this line right here, "react-native bundle --minify." We're going to jump over to our console, and we're going to paste that in, "react-native bundle --minify." We're going to run that.

Now we are going to get a handful of babel errors. This is a known issue that is being dealt with. There's an issue logged on GitHub for the React-Native project. Once that's completed, we now have a "main.js" bundle.

We can jump back over to our X-code, stop and restart our application. We need to go ahead and disable Chrome debugging. We'll stop that one more time and play it. Now we've got our application without any connection to our local machine.



HEY, QUICK QUESTION!
Joel's Head
Why are we asking?