When I tried to build and run, Xcode said my device was locked. I looked at my iPhone, and it\'s not locked at all. How do I fix this?
Another fix to this problem is to connect your iPhone with your Xcode open while your iPhone is in the homescreen, not in lockscreen or with an app opened.
When you plug in your iPhone, it will ask you to trust the computer. If you already trust and unlocked but still said your device was locked (bug). Just unplug and plug again then it will work
For those who has this issue in Xcode 9: Simply restarting Xcode should solve the problem.
Lots of answers, but the one that worked for me (El Capitan, Xcode 8.2) was to close iTunes. If that has a connection to the IOS device then although Xcode can load the app components it will still fail to run it.
sometimes your device stops trusting your PC for no reseaon. go to your settings then general > reset > reset location and privacy. and replug your device to your PC again and press "trust this device" prompt that shows up in your phone.
I found that by shutting down a Console and a running Simulator allowed XCode to see my iPhone again. I'd make sure other related programs aren't running if you don't need them.