Fix: Xcode Says Device Locked When iPhone is Unlocked

Fix: Xcode Says Device Locked When iPhone is Unlocked

Written by

in

Quick answer: To resolve the false ‘Device Locked’ state in Xcode, disconnect the physical cable, toggle your iPhone passcode lock on and off, reconnect the cable, and tap ‘Trust’ if prompted. If Xcode still fails to recognize the unlocked state, restart the macOS device management daemon by running killall -9 usbmuxd in Terminal.

Why this happens

When you build and run an iOS app directly onto a physical device, Xcode relies on secure communication channels managed by usbmuxd (the USB multiplexing daemon) and Developer Mode security policies. Before Xcode can attach LLDB to your app process, it verifies that the connected iPhone or iPad has established an authenticated, paired trust relationship with your Mac.

Even if your screen is turned on and displaying the Home Screen, Xcode reports Device Locked if the underlying cryptographic pairing handshake has stalled or expired. This commonly occurs after an iOS update, after clearing network settings, when switching USB ports, or when Developer Mode requires user re-authentication.

In some cases, the lock state is cached by CoreDevice or Xcode’s internal device cache. When the operating system fails to notify the host Mac that passcode entry succeeded, Xcode remains blocked waiting for confirmation that the hardware secure enclave has unlocked developer access.

How to fix it

1. Disconnect, Re-authenticate, and Reconnect

The most frequent cause is a stale connection session between Xcode and the iOS lock screen daemon. Resetting the session clears the temporary lock flag.

  1. Disconnect the Lightning or USB-C cable from your iPhone.
  2. Press the side button on your iPhone to manually lock the screen.
  3. Unlock the device using your passcode (avoid using only Face ID or Touch ID here, as a passcode entry explicitly unlocks the full data-protection keychain).
  4. Quit Xcode completely (Command + Q).
  5. Open Xcode and wait for your workspace to load.
  6. Reconnect the cable to your Mac.
  7. If the iPhone displays a prompt asking Trust This Computer?, tap Trust and enter your passcode.

Try running your project again with Command + R.

2. Verify Developer Mode Status on iOS

Starting in iOS 16 and continuing through modern iOS releases, Apple requires explicit activation of Developer Mode to run and debug local builds. If Developer Mode is disabled or pending a reboot, Xcode flags the device as inaccessible or locked.

  1. On your iPhone, open Settings.
  2. Navigate to Privacy & Security.
  3. Scroll to the bottom and select Developer Mode.
  4. Ensure the toggle is turned On.
  5. If you just toggled it on, restart the iPhone when prompted, unlock it with your passcode upon boot, and tap Turn On on the system confirmation dialog.
Settings > Privacy & Security > Developer Mode -> On

3. Reset the macOS USB Multiplexer Daemon (usbmuxd)

usbmuxd is responsible for coordinating USB and peer-to-peer Wi-Fi connections between macOS and connected Apple devices. When it hangs, Xcode cannot read the real-time lock state of your hardware.

Open Terminal on your Mac and terminate the daemon:

sudo killall -9 usbmuxd

launchd immediately restarts usbmuxd with a clean process table. Unplug your device, wait 5 seconds, and plug it back in. Xcode should detect the device status change within a few moments.

4. Unpair and Re-pair in Devices and Simulators

Corrupted pairing certificates between the Mac and iOS device prevent Xcode from acknowledging that the device is unlocked. Removing the device from Xcode’s paired inventory forces a fresh exchange of security keys.

  1. In Xcode, navigate to the menu bar and select Window > Devices and Simulators (or press Command + Shift + 2).
  2. Select your connected iPhone in the left sidebar under the Connected section.
  3. Right-click (or Control-click) your device name and select Unpair Device.
  4. Disconnect the cable from your Mac.
  5. On your iPhone, go to Settings > General > Transfer or Reset iPhone > Reset and select Reset Location & Privacy. This clears previous trust certificates.
  6. Reconnect the iPhone to your Mac via USB.
  7. Enter your passcode when the Trust This Computer? dialog appears on the screen.
  8. Return to Devices and Simulators and wait for Xcode to finish fetching symbols and setting up the device for development.

5. Clear Stale CoreDevice and DerivedData Caches

If the pairing record is valid but Xcode continues to display Device Locked, Xcode’s local cache of developer tools and provisioning sessions may be out of sync.

Quit Xcode, open Terminal, and remove the cached device and build state:

# Remove project-level DerivedData caches
rm -rf ~/Library/Developer/Xcode/DerivedData/*

# Reset Xcode's CoreDevice state (safe to remove; Xcode regenerates it on launch)
rm -rf ~/Library/Containers/com.apple.dt.CoreDevice.CoreDeviceService/Data/Library/Caches/*

Relaunch Xcode, open your project, and attempt the build again.

How to prevent it

  • Keep the screen awake during initial build indexing: When Xcode is installing provisioning profiles or transferring debug symbols, keep your iPhone display active until the debugger attaches.
  • Avoid unreliable USB hubs: Connect your test device directly to your Mac’s Thunderbolt or USB-C ports to avoid voltage drops and dropped multiplexing packets.
  • Use MFi-certified or official Apple cables: Faulty data pins on worn cables can deliver power while dropping communication packets midway through verification handshakes.
  • Avoid aggressive auto-lock timers: While actively debugging, consider setting your test device’s screen auto-lock interval to a longer duration under Settings > Display & Brightness > Auto-Lock.

FAQ

Why does Xcode say my device is locked when I am actively using it?

Xcode checks the authorization status between usbmuxd and the device’s secure enclave, not just whether the display is on. If the cryptographic trust pairing is missing or stuck in a handshake loop, Xcode treats the device as protected and locked.

Does this error happen over wireless debugging?

Yes. Wireless debugging relies on the same pairing credentials established during the initial USB connection. If your Wi-Fi connection drops packets or the local network handshake fails to complete, Xcode will display the device as locked or disconnected.

Will resetting ‘Location & Privacy’ delete any personal data on my iPhone?

No. Resetting Location & Privacy only clears granted system permissions (such as camera, location, and photo library prompts) and resets trusted computer pairings. It does not erase your apps, settings, photos, or personal data.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.