Xcode 16.4 Can't Attach to iPhone app for debugging

Xcode will transfer the app to the iPhone, and I can run it on the iPhone, but the Xcode debugger fails to attach. I am using iPhone 14 Pro with iOS 18.6.

I've tried connecting via cable, also via network - same issue both ways.

The message raised by Xcode says:

Could not attach to pid: "6303"

Ensure “<a\AppName>” is not already running, and <MyName> has permission to debug it.

I don't know how to determine if I have permission. I assume I do; I am the owner of the account, with admin role.

Answered by DTS Engineer in 855048022
I built a very basic test app from Xcode templates

That’s always a great diagnostic test. In this case it confirms that there’s something specific about your main project that’s causing this issue. I have some further suggestions:

  1. From the Home screen, remove your main app from the device.
  2. And then restart the device. These steps should remove any state leftover from any previous builds of the app.
  3. Do a clean build of the app.
  4. Do a Product > Run. Does it still reproduce the problem?
  5. Presuming it does, run the app from the Home screen and then do a Debug > Attach to Process. Does that work?

Also, after the rebuild in step 3, choose Product > Show Build Folder in Finder, then navigate to the Debug-iphoneos folder and, in Terminal, run this command:

% codesign -d --entitlements - MyApp.app
…
[Dict]
    …
    [Key] get-task-allow
    [Value]
        [Bool] true

As this code is Development signed, you should see the get-task-allow entitlement. This is what allows the debugger to attach.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

More info: I built a very basic test app from Xcode templates; it loads into the iPhone, and Xcode attaches to it successfully and enables debugging. So there is something my app is doing that prevents Xcode from attaching to it. My app:

  • supports carplay
  • plays audio
  • does not use storyboard, except for Launch storyboard
  • uses split view navigation

any suggestions or thoughts would be welcome.

Accepted Answer
I built a very basic test app from Xcode templates

That’s always a great diagnostic test. In this case it confirms that there’s something specific about your main project that’s causing this issue. I have some further suggestions:

  1. From the Home screen, remove your main app from the device.
  2. And then restart the device. These steps should remove any state leftover from any previous builds of the app.
  3. Do a clean build of the app.
  4. Do a Product > Run. Does it still reproduce the problem?
  5. Presuming it does, run the app from the Home screen and then do a Debug > Attach to Process. Does that work?

Also, after the rebuild in step 3, choose Product > Show Build Folder in Finder, then navigate to the Debug-iphoneos folder and, in Terminal, run this command:

% codesign -d --entitlements - MyApp.app
…
[Dict]
    …
    [Key] get-task-allow
    [Value]
        [Bool] true

As this code is Development signed, you should see the get-task-allow entitlement. This is what allows the debugger to attach.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for the reply. get-task-allow was false.

I realized that my profile needs to be a development profile, not a distribution profile. That must have been the reason get-task-allow was false. I can't set it to true otherwise.

Xcode 16.4 Can't Attach to iPhone app for debugging
 
 
Q