Let me share my story about a bug, which was driving me crazy for a week.

I made some modification in my app, tested it on simulators, even a device, and I sent the latest build for the internal TestFlight. When I installed the app on the same device I used to use for testing from Xcode, at a certain point the app went to the background, showing me the Home screen. I could see the app in the task switcher, where was actually showing properly the desired state of the application. When I tap on it to bring it forward as the main running app, the app went to the initial state, showing me the initial view controller. WTF? So I started the investigation with the steps below.

#1 Downloading the log files from your device

I thought: let’s investigate a bit… I connected my iPhone to my Mac, and started the Devices from Xcode -> Window -> Devices. Here I could see my phone, and be able to download the log files. I found nothing. Since I removed all of the NSLog entries from my code, there wasn’t even a log file form my application, so whatever happening with the app, it hasn’t been logged.

#2 Using Fabric and Crashlytics

My next try was with Fabric and Crashlytics, maybe it could catch something. I added to my project and started to work with them. The result? Nothing… 🙁

#3 Connecting the phone…

Since I am running out of ideas, I connected my iPhone again, and started the app from Xcode. It was working, of course, since my iPhone was like all of the other simulators. If I installed the version from TestFlight the problem appeared again.

#4 Eureka!

I started to think what is the difference between the different methods I used to deploy the app to my iPhone, and finally something clicked in about the Release and Debug builds.

By default Xcode compiles, deploys and starts your App with Debug executable enabled, when you run it on the device or on the simulator from Xcode.

When you upload your app into iTunes Connect, the app will be recompiled with the Release mode. And that made a huge different in my case.

At least I could be able to run the app with my device connected, and in the Console I can see only one last scream from my app, which helped me to hunt down the bug.

How to setup to run in release mode?

The main topic here is the Scheme, which is available under the Product menu point. In order to have the finally released build running on your device, you have to set up the scheme by the following:

Under the Run/Run:

– Build configuration: Release

– Untick Debug executable.

￼

Keep in mind, that although you are able to select the device (see the top left corner on the screen), it seems that is not the case. If you change the scheme, it will be applied for all of your devices. So when you finished with your testing, it is better to change it back to the default:

– Build configuration: Debug

– Tick Debug executable.

Like this: Like Loading...