How to Attach Debugger to iOS App After Launch

How to attach debugger to iOS app after launch?


  • Attach your device connected your Mac
  • Debug > Attach to Process by PID or Name
  • In the dialog sheet, enter the name of your App as it appears in the Debug navigator when started via Xcode (e.g. Target's name not bundle-id).

If the app is already running, the debugger will attach to the running process. If it isn't running, it will wait for the app to launch and then attach.

Debugging iOS app on first launch

Use the "Wait for MyApp.app to launch" option.

In Xcode, hold down the Option key and choose Product->Run... (the ellipses are added when you hold Option down). This will bring up the scheme editor, with the Run scheme selected. Click on the Info tab, and on the resulting Info panel you'll see a radio group labelled "Launch" with two options: "Automatically" and "Wait for MyApp.app to launch". If you select the second option, Xcode will start the debugger and wait for you to launch your application manually. You can set a breakpoint at the beginning of the code you want to debug, and the debugger will stop there.

Reset the app to its previous state.

You may want to consider adding some code that resets the app to whatever state it was in before the upgrade. This can be debug code that's excluded from the release build. Debugging problems that require you to re-install the app every time you want to run through your debug can take a lot of time. Even just having to restart the app at every debug cycle eats up a lot of your time. It's very often worthwhile to spend a little extra time adding a button to your app that undoes whatever changes you're making so that you can do them again.

Unit test.

One great way to debug code that deals with app states that are difficult to recreate is to write unit tests. In a test, you can create any state you want. You can even create app states that may be impossible to recreate in your app. And you can debug that code over and over again. Like the previous solution, it takes a little more time to write the code up front, but you'll save so much time on each iteration of your debug cycle that its well worth it. Even better, you can add the test to your build process so to help ensure that the functionality doesn't break later.

Attach debugger to an app cold-launching from a push notification

If you edit your build scheme and open the run options there are a pair of radio buttons called something like "Launch automatically" or "Wait for launch". You want the "wait for launch" option.

(I'm not at my Mac so I don't have the exact titles of the buttons. Sorry.)

Then when you run your app from the debugger it installs it and then Xcode sits and waits for an external event to launch the app. This facility is built for exactly what you're trying to do.

Debugging a Application Launch in Xcode and iOS

In the Scheme editor in Xcode, you can edit the Debug profile to have the debugger "Wait for XY.app to launch". If you then select Product -> Run, the debugger should wait until you launch the app manually on the device and then automatically attach to the running process.

How do I debug an iPhone app that's supposed to be launched by location services, into the background, from a terminated state?

Use Xcode’s Debug > Attach to Process > By Process Identifier (PID) or Name… menu: you can provide the name of your process and Xcode will then wait until it launches to attach and start a debug session.



Related Topics



Leave a reply



Submit