简体   繁体   English

Xcode iPhone 解锁时“设备已锁定”

[英]Xcode "Device Locked" When iPhone is unlocked

When I tried to build and run, Xcode said my device was locked.当我尝试构建和运行时,Xcode 说我的设备被锁定。 I looked at my iPhone, and it's not locked at all.我看了看我的 iPhone,它根本没有锁定。 How do I fix this?我该如何解决?

My phone was set to "trust" the Mac, and I still ran into this error with Xcode 6.1.1.我的手机设置为“信任”Mac,但我仍然在使用 Xcode 6.1.1 时遇到了这个错误。

This worked for me:这对我有用:

  • unplug device拔下设备
  • quit xcode退出 xcode
  • open xcode打开xcode
  • plug in device插入设备
  • build/run构建/运行

Did you by chance not "trust" the device?您是否偶然不“信任”该设备? This will prevent it from communicating with xcode even if the device is unlocked.即使设备已解锁,这也会阻止它与 xcode 通信。

Update here's a support doc from Apple: http://support.apple.com/en-us/HT5868更新这里是来自 Apple 的支持文档:http: //support.apple.com/en-us/HT5868

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.我最近在将我的设备从 iOS 9 更新到 10 之后遇到了 XCode 8 的这个问题。我收到的确切错误是: Development cannot be enabled while your device is locked. Please unlock your device and reattach. 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.正如几个答案中提到的, device is locked消息实际上是指设备不信任 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):就我而言,我认为我的手机在更新到 iOS 10 后默认不信任我的电脑。以下是我重置设置的步骤(这与教授回答中 Apple 支持页面中提到的过程相同):

  1. Disconnect your device from your MacBook and close Xcode.断开设备与 MacBook 的连接并关闭 Xcode。
  2. On your device go to Settings > General > Reset , then tap Reset Location & Privacy在您的设备上,前往Settings > General > Reset ”,然后点击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.现在重新打开 Xcode 并重建项目。
  5. The device locked error should disappear. device locked错误应该会消失。

From the Window Menu in top bar of Xcode, select Devices and Simulators.从 Xcode 顶部栏中的 Window Menu 中,选择 Devices and Simulators。

(or Press SHIFT + COMMAND + 2) (或按 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!等待 Xcode 配对设备进行开发,然后你就可以开始了!

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再次连接到 Mac

2018 2018

The fastest way for now i found is:现在我发现最快的方法是:

1) Go to Window -> devices (changed the hotkey in xcode to CMD+P for me) 1)转到窗口->设备(为我将xcode中的热键更改为CMD+P)
2) Press unpair on the device. 2) 按设备上的取消配对 在此处输入图像描述
3) Press trust in iPhone. 3) 在 iPhone 上按信任
4) Build again or Run without building (Ctrl+CMD+R) 4) 再次构建或不构建运行 (Ctrl+CMD+R)

Rebooted my iPhone, and that fixed it for me.重新启动我的 iPhone,并为我修复了它。

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.我尝试了此页面上的每个答案(当时有 7 个,虽然 2 个是重复的),但他们都没有成功为我摆脱这个 Xcode 错误。

I have a very simple solution which worked for me instantly.我有一个非常简单的解决方案,可以立即为我工作。 Takes some 10 sec to do:大约需要 10 秒才能完成:

1) Go to Window -> Devices & Simulators and untick Show as run destination 1) 转到Window -> Devices & Simulators并取消勾选Show as run destination

在此处输入图像描述

2) Unplug the cable and plug it back in. 2) 拔下电缆并将其重新插入。

3) Run the project. 3) 运行项目。

This should be solving your problem!这应该可以解决您的问题!

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.等待它并让 Xcode 检测您的设备。
  4. Run the project.运行项目。
  5. Make sure you TRUST on your iOS device and enter any passcode.确保您信任您的 iOS 设备并输入任何密码。

对于那些在 Xcode 9 中遇到此问题的人:只需重新启动 Xcode 即可解决问题。

This happens at times while using Xcode 9.在使用 Xcode 9 时有时会发生这种情况。

截屏

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.注意:确保您的设备在 Xcode 尝试安装应用程序时未锁定。

Solution 1 :解决方案 1:

i.一世。 Disconnect device and connect again Disconnect deviceconnect again

Solution 2 :解决方案 2:

i.一世。 Restart you device

Solution 3 :解决方案 3:

i.一世。 Disconnect device

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

iii. iii. Open your project

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

v. Now connect device v. 现在connect device

vi.六。 Run your project Run你的项目

For me Solution 3 worked perfectly对我来说,解决方案 3 效果很好

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.现在通过选择设备作为目标来运行 Xcode 项目。

When you plug in your iPhone, it will ask you to trust the computer.当您插入 iPhone 时,它​​会要求您信任计算机。 If you already trust and unlocked but still said your device was locked (bug).如果您已经信任并解锁但仍然说您的设备已锁定(错误)。 Just unplug and plug again then it will work只需拔下并重新插入,它就会工作

These steps worked for me in iOS 10.这些步骤在 iOS 10 中对我有用。

  1. Remove the cable from device.从设备上拔下电缆。
  2. Plug in the device.插入设备。
  3. Clean and build the Xcode project.清理并构建 Xcode 项目。

I run into this problem quite often (at least like 5 times a week).我经常遇到这个问题(至少每周 5 次)。 Almost every time this happens, a Xcode restart fixes it.几乎每次发生这种情况时,Xcode 重新启动都会修复它。 But this time nothing seemed to work including:但这一次似乎没有任何效果,包括:

  • Restarting Xcode;重启 Xcode;
  • Unplugging and re-plugging the iPhone;拔下和重新插入 iPhone;
  • Cleaning the project (cmd+shift+k);清理项目(cmd+shift+k);
  • Cleaning derived data (cmd+option+shift+k)清理派生数据(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. ✅ 重新启动 Mac。

Recently I have met the Xcode shows "development cannot be enabled while your device is locked, Please unlock your device and reattach. (0xE80000E2).最近我遇到Xcode显示“当您的设备被锁定时无法启用开发,请解锁您的设备并重新连接。(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.如果您的 iOS 设备已经解锁并连接到 mac,并且在升级到 iOS 10.1.1 后仍然从 Xcode 8.1 收到错误,则该 mac 不受设备信任。

To fix it, first disconnect device to mac and then go to iOS settings app, and open general->reset->Reset Location & Privacy.要修复它,首先断开设备与 mac 的连接,然后转到 iOS 设置应用程序,然后打开常规->重置->重置位置和隐私。

Then connect device to mac and when prompted, set select trust the mac.然后将设备连接到 mac,并在出现提示时设置选择信任 mac。

Then wait the processing symbol files within your device and mac.然后等待您的设备和 mac 中处理符号文件。 After it finished, you can run the project to your device.完成后,您可以将项目运行到您的设备上。 It will be working.它会起作用的。

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!!!在您的 iPhone 设备中转到设置 > 开发人员 > 单击“清除受信任的计算机”输入所需的密码并完成!!!

The simplest way that I found.我找到的最简单的方法。

This issue is not about "Trust" or not.这个问题与“信任”与否无关。 It's a bug in Xcode.这是 Xcode 中的一个错误。

Just follow these steps.只需按照以下步骤操作。

When Xcode is running and your device is connected:当 Xcode 正在运行并且您的设备已连接时:

  1. Lock your device.锁定您的设备。
  2. Unplug your device from Mac.从 Mac 上拔下您的设备。
  3. Unlock your device.解锁您的设备。
  4. Plug your device back to Mac.将您的设备插回 Mac。

Solution : Switch target device to some other (eg Generic iOS Device),解决方案:将目标设备切换到其他设备(例如通用 iOS 设备),

在此处输入图像描述

then unlock you physical device and switch back to it again.然后解锁您的物理设备并再次切换回它。

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.但今天它没有,其他东西似乎起作用了:我已经在有问题的设备上启用了网络调试,它几乎看起来像是记住了一个旧的网络“锁定”设置,而没有看到该设备实际上是通过 USB 连接的. After (temporarily) de-selecting " Connect via Network " and replugging, it got things working again.在(暂时)取消选择“通过网络连接”并重新插入后,它又可以正常工作了。

there are two solution worked for me.有两个解决方案对我有用。 1) disconnect your device from the mac and reattach it. 1)断开您的设备与Mac的连接并重新连接。 2) disconnect your device from the mac and restart it and then connect it with mac it'll work 2)断开您的设备与mac并重新启动它,然后将它与mac连接它会工作

sometimes your device stops trusting your PC for no reseaon.有时您的设备会无缘无故停止信任您的 PC。 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.并再次将您的设备重新插入您的 PC,然后按手机中显示的“信任此设备”提示。

Lots of answers, but the one that worked for me (El Capitan, Xcode 8.2) was to close iTunes.很多答案,但对我有用的一个(El Capitan,Xcode 8.2)是关闭 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.如果它与 IOS 设备有连接,那么尽管 Xcode 可以加载应用程序组件,但它仍然无法运行它。

在您的设备(iPhone/iPad)上转到:设置->开发人员->清除受信任的计算机为我工作。

I found that by shutting down a Console and a running Simulator allowed XCode to see my iPhone again.我发现通过关闭控制台和正在运行的模拟器可以让 XCode 再次看到我的 iPhone。 I'd make sure other related programs aren't running if you don't need them.如果您不需要其他相关程序,我会确保它们没有运行。

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).这也意味着您需要更新手机,连接到 MacBook(如果需要,请相信它)。 This how I found my problem and solution.这就是我发现问题和解决方案的方式。

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. Xcode 不会给您一个有用的“设备已满”错误来告诉您您的设备没有剩余存储空间,但它也无法将应用程序构建部署到存储已满的设备。 The only solution in that situation is to delete media or other apps/data to free up enough space.在这种情况下,唯一的解决方案是删除媒体或其他应用程序/数据以释放足够的空间。

解决此问题的另一个方法是在 iPhone 处于主屏幕而不是锁屏或打开应用程序时连接您的 iPhone 并打开 Xcode。

All the previous solutions didn't work.以前的所有解决方案都不起作用。

Finlay, changing the iPhone's cable solved the problem. Finlay,更换 iPhone 的电缆解决了这个问题。

I had to re-add device to xcode.我不得不将设备重新添加到 xcode。

In XCode open Devices and Simulators (CMD+Shift+2), in left list press + button and re-add the same device.在 XCode 中打开设备和模拟器 (CMD+Shift+2),在左侧列表中按 + 按钮并重新添加相同的设备。

Check the "Low Power Mode" in disabled.检查禁用的“低功耗模式”。 In my case I just disable this check and the deploy works immediately,就我而言,我只是禁用此检查,然后部署立即生效,

Bizare, but I hope it helps someone.奇怪,但我希望它可以帮助某人。 I was connected to a VPN (Pro XPN) and that was causing the issue!我已连接到 VPN(Pro XPN),这就是问题所在! Disconnected and it worked.断开连接,它工作。

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."对我来说,当我准备从 xcode 取消配对我的设备时,我注意到它只是为我的 iPhone 准备调试器支持,它告诉我“iPhone 完成后 Xcode 将继续。” Similar to this issue类似于这个问题

Check that on the "Runner" option is selected the correct device.检查是否在“Runner”选项上选择了正确的设备。 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.尽管您有一台设备通过电缆物理插入,但 Xcode 可以通过 WiFi 连接到任何其他启用了“通过网络连接”选项的设备。

检查“Runner”设备(“build & run”之后的左上第三个按钮,以及“stop”按钮)

My problem was I was trying to install on an unsupported (new) iOS version which produced the same errors.我的问题是我试图安装在产生相同错误的不受支持的(新)iOS 版本上。 Specifically Xcode 11.7 to iOS 14特别是 Xcode 11.7 到 iOS 14

对我来说,我的 iPhone 12 有一个连接的 Apple Watch,我也必须信任我的 Apple Watch 上的电脑。

There is no simple solution.没有简单的解决方案。 The only real solution is to reboot the Mac, restart XCode and the iPhone.唯一真正的解决方案是重启 Mac,重启 XCode 和 iPhone。 This is a shame, because it can happen at any time even in the middle of a session where everything was perfectly working, device paired and unlocked as needed.这是一种耻辱,因为它可能随时发生,即使在一切正常工作、设备根据需要配对和解锁的会话中也是如此。 All other solutions given here or elsewhere can work here and now but fail tomorrow morning.此处或其他地方给出的所有其他解决方案都可以在此时此地工作,但明天早上就会失败。

I spent hours trying to fix this issue with no luck.我花了几个小时试图解决这个问题,但没有成功。

BE SURE TO DISABLE ANY VPN SERVICES FROM YOUR IPHONE.请务必从您的 IPHONE 禁用任何 VPN 服务。 Just like magic, it started working properly.就像魔术一样,它开始正常工作。

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.我在这里的任何答案中都没有看到这一点,但唯一对我有用的是设备本身的一个选项,称为启用 UI 自动化。 Supposedly it will turn itself off after an update.据说更新后它会自行关闭。 Go to Settings, Developer, then find Enable UI Automation.转到设置,开发人员,然后找到启用 UI 自动化。

This worked on my iPad 6th generation.这适用于我的第 6 代 iPad。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM