349

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?

kit
  • 1,108
  • 5
  • 14
  • 22
Faisal Syed
  • 3,561
  • 2
  • 9
  • 10

37 Answers37

481

My phone was set to "trust" the Mac, and I still ran into this error with Xcode 6.1.1.

This worked for me:

  • unplug device
  • quit xcode
  • open xcode
  • plug in device
  • build/run
Abhi Beckert
  • 30,929
  • 11
  • 77
  • 106
  • 80
    Unfortunately this is too often the solution for many of your weird Xcode woes. – Jarsen Dec 20 '15 at 03:58
  • "did you try turning it off and on again?!" - works every time! – mike james Jan 14 '19 at 15:12
  • 3
    November 2019 and Xcode still has this problem! It hit me this morning. unplug device, quit Xcode, (go get more coffee), open Xcode, plug in, big time sink but seems to work. My other "favorite" is Xcode sees the device then doesn't see the device. – WholeCheese Nov 20 '19 at 19:17
  • 1
    XCode 10.1 and still had to do this to get it to deploy to device. Some things never change. – CasualCoder Feb 11 '20 at 22:30
  • 1
    as of the latest Xcode 11.4.1... this is till the answer – rickrvo May 11 '20 at 02:49
  • 1
    If this does not work, just turn off and turn on the device again. It worked for me in Xcode 12 and Ipad with Ios 14 – Kevin Oswaldo Jan 22 '21 at 22:01
149

Did you by chance not "trust" the device? This will prevent it from communicating with xcode even if the device is unlocked.

Update here's a support doc from Apple: http://support.apple.com/en-us/HT5868

tehprofessor
  • 2,739
  • 1
  • 18
  • 21
  • 2
    I'm not sure what you mean by "trust"...how do i enable that? – Faisal Syed Nov 06 '14 at 23:59
  • 93
    Unplug the device, close xcode, and then open xcode and plugin the device. When you plug it in (after unlocking it) it you should be prompted to "trust" the computer (in the iOS device). My guess is you may have accidentally tapped "do not trust" and so the device will refuse to connect to the computer. – tehprofessor Nov 07 '14 at 00:01
  • 1
    I've updated the answer with a link to apple support page regarding the issue. – tehprofessor Nov 07 '14 at 00:02
  • This is really weird because in my case, I was never prompted to trust in the first place... – Nicolas Miari Jun 06 '18 at 02:57
  • 1
    @NicolasMiari I've had other notifications show up at the same time I plug in my phone causing it disappear, or accidentally dismissing the prompt on my Mac... as well, if you've used mobile configurator there is a chance it's causing some weird issues as the device could be configured to only respond to one machine. Perhaps that handshake got messed up the first time you plugged it in? – tehprofessor Jun 07 '18 at 21:13
  • There is also an additional step to run the app on phone , you have to trust the developer profile inside your iPhone settings . – Sainath S.R Jun 23 '18 at 13:47
  • 3
    Ah ... another one of those "jiggle the switch" solutions. – Zmart Sep 19 '18 at 16:09
  • @tehprofessor I didn't need to tap Trust again since the computer was already trusted, but your advice to "Unplug the device, close xcode, and then open xcode and plugin the device" worked. Thanks! – CasualCoder Dec 12 '18 at 17:25
  • 1
    Adding for this solution: If the "Trust" popup doesn't appear, in Xcode go to "Devices & Simulator" -> Unpair your device, and then unplug and plug, the "Trust" popup should appear. – Issa Oct 26 '19 at 14:57
114

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):

  1. Disconnect your device from your MacBook and close Xcode.
  2. On your device go to Settings > General > Reset, then tap Reset Location & Privacy
  3. Plug your device back into your computer, and on the device you will be prompted to trust the computer. Tap trust.
  4. Now reopen Xcode and rebuild the project.
  5. The device locked error should disappear.
alex_lewis
  • 2,491
  • 3
  • 17
  • 47
Iron John Bonney
  • 2,077
  • 1
  • 13
  • 12
  • yep unfortunately only this worked for me on from Xcode 8 on iOS 10 :( – Bishal Ghimire Oct 25 '16 at 03:41
  • @BishalGhimire Yeah, it's definitely not ideal. I actually just had to do this reset again as XCode started giving me the `device is locked` message again without any noticeable changes to any of my iPhone's settings or XCode's settings. Somewhere along the way my trust settings for my computer are being reset, but I'm not sure when and where. – Iron John Bonney Oct 25 '16 at 19:16
  • 3
    you should wait for a while to processing symbol files – Hamed Ghadirian Nov 20 '16 at 07:22
  • Hmm... this fixed the "Device Locked" error ... but has replaced it with a "Could not save the pairing record." error ... – kris Dec 20 '16 at 04:22
  • 2
    this worked for me after iOS 11 software update on device / Xcode 9 – Ben Oct 18 '17 at 10:22
  • This appeared to work for me at first as it did prompt me to trust my computer again, I had to enter my password, it paired, but now it says that my device has denied the request. It's interesting to note as well that despite it not launching a debug session it would install and launch the app from Xcode as if the device was already trusted. I really don't know what to do at this point other than try a factory reset. – David Greco Jul 19 '18 at 22:25
  • Thank you so much for that! In Russian, it was "geolocation" menu item. Worked for me. – Nadia Solovyeva Sep 16 '20 at 12:09
  • Thanks, this worked for me! – adamsfamily Feb 18 '21 at 21:09
70

From the Window Menu in top bar of Xcode, select Devices and Simulators.

(or Press SHIFT + COMMAND + 2)

Then select your device, right click and select Unpair.
Once you do this Trust or Don't trust will appear on your device.
Trust the device again and it will begin preparing it for Development.
Wait for Xcode to pair device for development and then you are good to go!

Asfand Shabbir
  • 1,046
  • 11
  • 9
42

I ran in to the same issue even though i selected "Trust this computer" option first time.

This worked for me

  1. Lock the device
  2. Remove cable from device.
  3. Unlock the device
  4. Connect again to Mac
Itzdsp
  • 826
  • 9
  • 19
33

2018

The fastest way for now i found is:

1) Go to Window -> devices (changed the hotkey in xcode to CMD+P for me)
2) Press unpair on the device. enter image description here
3) Press trust in iPhone.
4) Build again or Run without building (Ctrl+CMD+R)

Nik Kov
  • 10,605
  • 4
  • 56
  • 96
21

For anyone who need a logical answer..

  1. Go to Window -> Devices & Simulators. Right click on your device & unpair it.
  2. Disconnect from cable & reconnect.
  3. Wait for it & let Xcode detect you device.
  4. Run the project.
  5. Make sure you TRUST on your iOS device and enter any passcode.
Amber K
  • 683
  • 1
  • 5
  • 15
  • This worked. Make sure your device is UNLOCKED when you initially pair it. If not then follow these instructions to repair. – Wizkid May 14 '18 at 15:29
18

Rebooted my iPhone, and that fixed it for me.

I tried every answer on this page (7 at the time, though 2 are duplicates) and they were all unsuccessful for getting rid of this Xcode error for me.

Community
  • 1
  • 1
kris
  • 9,422
  • 6
  • 66
  • 90
18

I have a very simple solution which worked for me instantly. Takes some 10 sec to do:

1) Go to Window -> Devices & Simulators and untick Show as run destination

enter image description here

2) Unplug the cable and plug it back in.

3) Run the project.

This should be solving your problem!

Starsky
  • 1,113
  • 7
  • 15
  • 1
    Thanks, this worked for me with XCode 10.2 when the other advice didn't. May be related to having previously ticked to be available over network then being on a rather slow wifi. – Andy Dent Oct 01 '19 at 05:30
  • Thanks. This worked for me. Xcode 11.3. Funny because unplugging the cable and plugging it back in didn't work, when I didnt open Devices & Simulators window. – Lazy Ninja Jan 23 '20 at 05:51
  • Um, that seems to just make it not be available to select as the destination. What am I missing? – Dronz Feb 13 '20 at 05:57
  • Most probably you forgot to follow the 2nd step: ```2) Unplug the cable and plug it back in. Run the project.``` – Starsky Feb 13 '20 at 08:03
12

For those who has this issue in Xcode 9: Simply restarting Xcode should solve the problem.

Vlad Papko
  • 12,848
  • 4
  • 38
  • 52
12

This happens at times while using Xcode 9.

Screenshot

There are multiple solution to this as mentioned below :

Note : Make sure that your device is not locked when Xcode is trying to install app.

Solution 1 :

i. Disconnect device and connect again

Solution 2 :

i. Restart you device

Solution 3 :

i. Disconnect device

ii. Quit Xcode (Shortcut key : cmd + Q)

iii. Open your project

iv. Clean project (Shortcut key : cmd + shift + K)

v. Now connect device

vi. Run your project

For me Solution 3 worked perfectly

Jayprakash Dubey
  • 32,447
  • 16
  • 161
  • 169
  • Tried just about everything in the book. Restarting my phone was the only thing that worked in the end. Thanks for posting that idea here! – Brian Sachetta Oct 22 '20 at 15:04
11

A simple solution:

  1. First, unplug your device.

  2. Now, unlock your device and plug it in again. Be sure that the device is unlocked.

  3. Now run the Xcode project by selecting the device as target.

Pang
  • 8,605
  • 144
  • 77
  • 113
jaiswal Rajan
  • 4,291
  • 1
  • 24
  • 16
8

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

Keeley
  • 81
  • 2
8

These steps worked for me in iOS 10.

  1. Remove the cable from device.
  2. Plug in the device.
  3. Clean and build the Xcode project.
Pang
  • 8,605
  • 144
  • 77
  • 113
Jhansi M
  • 81
  • 1
  • 1
6

Recently I have met the Xcode shows "development cannot be enabled while your device is locked, Please unlock your device and reattach. (0xE80000E2).

If your iOS device is already unlocked and connected to mac and still get the error from Xcode 8.1 after upgrading to iOS 10.1.1, then the mac is not trusted by the device.

To fix it, first disconnect device to mac and then go to iOS settings app, and open general->reset->Reset Location & Privacy.

Then connect device to mac and when prompted, set select trust the mac.

Then wait the processing symbol files within your device and mac. After it finished, you can run the project to your device. It will be working.

Deepin.Do
  • 61
  • 1
  • 2
6

This issue is not about "Trust" or not. It's a bug in Xcode.

Just follow these steps.

When Xcode is running and your device is connected:

  1. Lock your device.
  2. Unplug your device from Mac.
  3. Unlock your device.
  4. Plug your device back to Mac.
Pang
  • 8,605
  • 144
  • 77
  • 113
Tom
  • 255
  • 1
  • 3
  • 6
6

I run into this problem quite often (at least like 5 times a week). Almost every time this happens, a Xcode restart fixes it. But this time nothing seemed to work including:

  • Restarting Xcode;
  • Unplugging and re-plugging the iPhone;
  • Cleaning the project (cmd+shift+k);
  • Cleaning derived data (cmd+option+shift+k)

Done dozens of times in all sorts of different orders.

What fixed the issue for me this time was simply:

✅ Rebooting the Mac.

Roger Oba
  • 652
  • 6
  • 20
4

Solution: Switch target device to some other (e.g. Generic iOS Device),

enter image description here

then unlock you physical device and switch back to it again.

Petr Lazarev
  • 2,604
  • 18
  • 17
4

There is a simple way to resolve that. At least it works for me. In your iPhone Device Go to Setting > Developer > click in “Clear Trusted Computer” Type the passcode required And done!!!

The simplest way that I found.

3

Generally just unplugging/replugging seems to work for me. But today it didn't and something else seems to have worked: I have enabled network debugging on the device in question and it almost looked like it remembered an old network "lock" setting, while not seeing that the device was actually connected via USB. After (temporarily) de-selecting "Connect via Network" and replugging, it got things working again.

LZM
  • 139
  • 1
  • 8
3

there are two solution worked for me. 1) disconnect your device from the mac and reattach it. 2) disconnect your device from the mac and restart it and then connect it with mac it'll work

Ahsan
  • 392
  • 3
  • 9
1

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.

brianlmerritt
  • 2,095
  • 1
  • 27
  • 36
1

On your device (iPhone/iPad) goto: Settings -> Developer -> Clear Trusted Computers worked for me.

Chaudhry Talha
  • 4,570
  • 7
  • 30
  • 71
Mateusz Kaflowski
  • 1,705
  • 1
  • 21
  • 30
  • this is what I had to do as well to get the 'trust this computer?' prompt to appear when I connected to my computer – Nunchucks Jun 26 '18 at 20:31
1

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.

Paul K.
  • 67
  • 1
  • 12
1

This can also happen due to pending update on your device. This also means you need to update your phone, connect to the MacBook (trust it if needed). This how I found my problem and solution.

Atarang
  • 402
  • 1
  • 6
  • 19
  • I had the same problem (update was waiting on device) but I didn't have time to update it. Asfand Shabbir's answer worked. (in case readers don't have time to update) – Can Poyrazoğlu May 06 '18 at 10:55
1

One possibility worth checking, if none of these other solutions work, is that there is no space left on the device. Xcode will not give you a helpful "device full" error to tell you that your device has no storage space left, but it will also not be able to deploy an app build to a device whose storage is full. The only solution in that situation is to delete media or other apps/data to free up enough space.

0

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.

0

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.

yannisalexiou
  • 465
  • 10
  • 21
0

All the previous solutions didn't work.

Finlay, changing the iPhone's cable solved the problem.

AL3MS
  • 91
  • 2
  • 8
0

I had to re-add device to xcode.

In XCode open Devices and Simulators (CMD+Shift+2), in left list press + button and re-add the same device.

Martin Janeček
  • 420
  • 3
  • 15
0

Check the "Low Power Mode" in disabled. In my case I just disable this check and the deploy works immediately,

0

Bizare, but I hope it helps someone. I was connected to a VPN (Pro XPN) and that was causing the issue! Disconnected and it worked.

Karl Gjertsen
  • 4,097
  • 8
  • 35
  • 61
0

For me, when I was about to unpair my device from xcode, I noticed it was just Preparing debugger support for my iPhone and it told me that "Xcode will continue when iPhone is finished." Similar to this issue

salouri
  • 697
  • 6
  • 17
0

Check that on the "Runner" option is selected the correct device. Although you have one device physically plugged in with a cable, Xcode could have connected via WiFi to any other device that has the "Connect via network" option enabled.

Check the "Runner" device (3rd Top Left button after the "build & run", and the "stop" buttons)

Mengrolek
  • 91
  • 2
  • 2
0

My problem was I was trying to install on an unsupported (new) iOS version which produced the same errors. Specifically Xcode 11.7 to iOS 14

user139816
  • 193
  • 13
0

For me my iPhone 12 has a connected Apple Watch, I had to trust my computer on my Apple Watch as well.

wz366
  • 2,251
  • 3
  • 21
  • 27
-1

I haven't seen this in any of the answers here, but the only thing that worked for me is an option on the device itself called Enable UI Automation. Supposedly it will turn itself off after an update. Go to Settings, Developer, then find Enable UI Automation.

This worked on my iPad 6th generation.

Justa Guy
  • 1
  • 2