I recently ran into this issue with XCode 8 just after updating my device from iOS 9 to 10. The exact error I received was:
Development cannot be enabled while your device is locked. Please unlock your device and reattach. I received this error even when my phone was unlocked, and after unplugging and re-plugging in the device.
As is mentioned in several answers, the
device is locked message is actually referring to the device not trusting the MacBook. In my case, I think my phone defaulted to not trusting my computer after updating to iOS 10. Here are the steps that worked for me to reset the settings (this is the same process that is mentioned in the Apple support page in tehprofessors' answer):
- Disconnect your device from your MacBook and close Xcode.
- On your device go to
Settings > General > Reset, then tap
Reset Location & Privacy
- Plug your device back into your computer, and on the device you will be prompted to trust the computer. Tap trust.
- Now reopen Xcode and rebuild the project.
device locked error should disappear.