xcode 在真正的 Apple Watch 上调试 WatchKit - 没有任何反应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31741744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug WatchKit on real Apple Watch - Nothing happens
提问by Andrei Herford
I am struggling with debugging my WatchKit Extension/App on a real Apple Watch. Debugging both the iPhone App and the WatchKit Extension using the simulator the simulator is not problem:
我正在努力在真正的 Apple Watch 上调试我的 WatchKit 扩展程序/应用程序。使用模拟器调试iPhone App和WatchKit Extension都没有问题:
- Select the WatchKit App Profile and run in Simulator ==> App is launched on in Watch Simulator and I can use breakpoints in the Extension codeto debug.
- To debug the iPhone app as well I launch the app in the simulator and attach the debugger manually ==> I can use breakpoints in the iPhone Codeto debug.
- 选择 WatchKit App Profile 并在模拟器中运行 ==> App 在 Watch Simulator 中启动,我可以使用扩展代码中的断点进行调试。
- 为了调试 iPhone 应用程序,我在模拟器中启动应用程序并手动附加调试器 ==> 我可以使用iPhone 代码中的断点进行调试。
It is no problem to observe both the work of the iPhone app and the watch app. At least not in the simulator.
观察iPhone应用程序和手表应用程序的工作是没有问题的。至少不是在模拟器中。
I would like to do the same thing on a real Apple Watch. But when I select the WatchKit App Profile and my real iPhone (instead of the Simulator) and click on "Run" nothing happens. This means Xcode seems to build and start the app but nothing happens on the devices. The status field in Xcode shows:
我想在真正的 Apple Watch上做同样的事情。但是当我选择 WatchKit 应用程序配置文件和我真正的 iPhone(而不是模拟器)并单击“运行”时,什么也没有发生。这意味着 Xcode 似乎构建并启动了应用程序,但设备上没有任何反应。Xcode 中的状态字段显示:
Building MyApp WatchKit App: MyApp WatchKit Extension
Building MyApp WatchKit App: Finishing...
Running MyApp on My iPhone 6
构建 MyApp WatchKit 应用程序:MyApp WatchKit 扩展
构建 MyApp WatchKit 应用程序:完成...
在我的 iPhone 6 上运行 MyApp
This is all. No debug Window, breakpoints are ignored or do not work and the app is not launched neither on the iPhone or on the Apple Watch.
这就是全部。没有调试窗口,断点被忽略或不起作用,应用程序既不在 iPhone 上也不在 Apple Watch 上启动。
I found other questions about problems with debugging on real devices (e.g. here) but they all deal with installation and signing issues. In my case both the iPhone App and the WatchKit App are installed without any problem. When I click the app icon on the Watch I can start and use the app. Problem is that I cannot debug this process.
我发现了有关在真实设备上调试问题的其他问题(例如此处),但它们都涉及安装和签名问题。就我而言,iPhone 应用程序和 WatchKit 应用程序都安装没有任何问题。当我单击 Watch 上的应用程序图标时,我可以启动并使用该应用程序。问题是我无法调试这个过程。
Why do I need to debug the process on real devices?Well there is one thing I cannot test using the simulator: What happens when the Watch App tries to contact the iPhone app using openParentApplication:reply:
when the iPhone app is not already running? This works perfectly in the simulator but on real devices the Watch Apps seems to get no reply from the iPhone app and simply waits forever.
为什么需要在真机上调试进程?好吧,我无法使用模拟器测试一件事:当 Watch 应用程序尝试使用openParentApplication:reply:
iPhone 应用程序尚未运行时联系 iPhone 应用程序时会发生什么?这在模拟器中完美运行,但在真实设备上,Watch Apps 似乎没有得到 iPhone 应用程序的回复,只是一直等待。
I already found hintsto solve this but without being able to debug the Watch App and to see how the code is executed I cannot be sure what is going on...
我已经找到了解决这个问题的提示,但无法调试 Watch App 并查看代码是如何执行的,我无法确定发生了什么......
采纳答案by Andrei Herford
thank you for your answers. I finally managed to get the debugging running (most of the time) on my real Apple Watch. However it is quite cumbersome and not very reliable. There is not enough space in the comments so I will use this answer to describe my solution. Maybe it is help full to other:
谢谢您的回答。我终于设法在我真正的 Apple Watch 上运行调试(大部分时间)。然而,它非常麻烦并且不是很可靠。评论中没有足够的空间,因此我将使用此答案来描述我的解决方案。也许它对其他人有帮助:
- Make sure, the App on your Watch is not running (as BalestraPatrick described). Launch the app and hold the side button a few seconds to bring up the "Turn off your Watch" dialog. Hold the side button for another few seconds to close the app and to return to the Watch homescreen.
Make sure the iPhone is not locked.
Select the
WatchKit App
target and your real iPhone and run the project.- Running the Watch App resulted quite often in an error
SPErrorInvalidBundleNoGizmoBinaryMessage
. Re-starting Xcode and cleaning both the Watch App and the App target solved this. - If the build of the Watch App succeed there will be a short message in Xcode but nothing on your iPhone or Watch. If you have made changes to the Watch App it will take a few seconds to refresh the app on the Watch. This is indicated by the progress-circle overlay over the app icon. If you made no changes ore once the app has been transfered: Launch the watch app manually by tapping the icon. There will be no automatic launch.
- In most cases Xcode will recognize the app launch and attach its debugger to it. This will allow to use breakpoints, inspect the code, etc.
- 确保手表上的应用程序没有运行(如 BalestraPatrick 所述)。启动应用程序并按住侧边按钮几秒钟以显示“关闭手表”对话框。再按住侧边按钮几秒钟以关闭应用程序并返回 Watch 主屏幕。
确保 iPhone 没有被锁定。
选择
WatchKit App
目标和您的真实 iPhone 并运行该项目。- 运行 Watch 应用程序经常导致错误
SPErrorInvalidBundleNoGizmoBinaryMessage
。重新启动 Xcode 并清理 Watch App 和 App 目标解决了这个问题。 - 如果 Watch 应用程序构建成功,Xcode 中将显示一条短消息,但您的 iPhone 或 Watch 上将没有任何消息。如果您对 Watch 应用程序进行了更改,则需要几秒钟时间来刷新 Watch 上的应用程序。这由应用程序图标上的进度圈覆盖指示。如果您在转移应用程序后未进行任何更改:通过点按图标 手动启动手表应用程序。不会有自动启动。
- 在大多数情况下,Xcode 会识别应用程序启动并将其调试器附加到它。这将允许使用断点、检查代码等。
In my case I whanted to inspect how the iPhone App handles the application:handleWatchKitExtensionRequest:reply:
call when the app was not active before. This is important because this cannot be done using the simulator. If the app takes to long to handle the request the Watch will receive no valid response.
就我而言,我想检查 iPhone 应用程序application:handleWatchKitExtensionRequest:reply:
在应用程序之前未处于活动状态时如何处理呼叫。这很重要,因为这无法使用模拟器完成。如果应用程序需要很长时间来处理请求,Watch 将不会收到有效响应。
After following the steps described above Xcode is only attached the watch app and will not hold on breakpoints in the iPhone app code. To do this, one has to manually attach the Debugger to the iPhone app process that is started when the watch app sends its call.
按照上述步骤操作后,Xcode 只会附加手表应用程序,而不会保留 iPhone 应用程序代码中的断点。要做到这一点,必须手动将调试器附加到手表应用程序发送调用时启动的 iPhone 应用程序进程。
To be able to attach the debugger I added a delay to the apps main function: [NSThread sleepForTimeInterval:5]
:
为了能够附加调试器,我在应用程序主函数中添加了一个延迟[NSThread sleepForTimeInterval:5]
::
- Select function in Watch App that will start the call to the iPhone App
- The iPhone App will be launched in background. The delays gives you 5 seconds to attach the debugger.
- Choose
Debug\Attach To Process\Likely Targes\Your iPhone App
in Xcode to attach the debugger. - After the 5 seconds delay the process will continue and you will be able to use breakpoints in your iPhone app code as well.
- Do not forget do remove the delay code when you finished testing :-)
- 在 Watch App 中选择将开始呼叫 iPhone App 的功能
- iPhone 应用程序将在后台启动。延迟为您提供了 5 秒的时间来连接调试器。
Debug\Attach To Process\Likely Targes\Your iPhone App
在 Xcode 中选择以附加调试器。- 延迟 5 秒后,该过程将继续,您也可以在 iPhone 应用程序代码中使用断点。
- 完成测试后不要忘记删除延迟代码:-)
NOTE:You will not be able to see NSLog
output (or any console output at all) from the iPhone App since attaching the debugger does NOT re-route the console output.
注意:您将无法看到NSLog
iPhone 应用程序的输出(或任何控制台输出),因为附加调试器不会重新路由控制台输出。
Happy testing with this awesome new Apple product :-P
用这款很棒的 Apple 新产品进行愉快的测试:-P
回答by BalestraPatrick
I am having the same kind of issue but to improve a little bit the debugging experience I usually restart my devices a few times. Try to restart your Apple Watch or your iPhone.
我遇到了同样的问题,但为了稍微改善调试体验,我通常会重启我的设备几次。尝试重新启动 Apple Watch 或 iPhone。
Before launching your app from Xcode, make sure that the app is completely closed on your Apple Watch (not stuck in the loading screen for example). To do that, you have to force close the app: enter your app, keep the side button pressed until the menu to turn off the watch appears, then press the same side button for a few more seconds until the watch will go back to the homescreen and force close your app.
在从 Xcode 启动您的应用程序之前,请确保该应用程序在您的 Apple Watch 上完全关闭(例如,不会卡在加载屏幕中)。为此,您必须强制关闭应用程序:进入您的应用程序,按住侧边按钮直到出现关闭手表的菜单,然后再按同一个侧边按钮几秒钟,直到手表返回主屏幕并强制关闭您的应用程序。
Now you can try to build and run the app from Xcode and it should work more reliably.
现在您可以尝试从 Xcode 构建和运行应用程序,它应该会更可靠地工作。
watchOS 3+:
watchOS 3+:
The force quit is done by pressing and holding the side button (the button just below the Digital Crown) until the shutdown screen appears, and then let go of the side button, then press and hold the Digital Crown.
强制退出是通过按住侧面按钮(数码表冠正下方的按钮)直到出现关机屏幕,然后松开侧面按钮,然后按住数码表冠来完成的。
回答by Jay Hickey
Here's a technique that seems to be be the most reliable for me, even though it still only works about 25% of the time (Xcode 7 beta 4, 7A165t):
这是一种对我来说似乎最可靠的技术,尽管它仍然只有大约 25% 的时间有效(Xcode 7 beta 4, 7A165t):
- Run the phone target in debug (on your actual iPhone of course)
- While the iPhone app is still running, switch to the watch target and run that in debug.
- Keep an eye on your watch homescreen as the app installs. Once the app has installed, tap it to open it. This will sometimes "kickstart" the watch app and allow the debugger to catch it. At this point you should be able to debug both your iPhone app and watchOS app together.
- 在调试中运行手机目标(当然在您的实际 iPhone 上)
- 当 iPhone 应用程序仍在运行时,切换到 watch 目标并在调试中运行它。
- 安装应用程序时,请留意手表主屏幕。安装应用程序后,点击它以将其打开。这有时会“启动”手表应用程序并允许调试器捕获它。此时,您应该能够同时调试您的 iPhone 应用程序和 watchOS 应用程序。
回答by Gerd Castan
This question has different answers. All are good.
这个问题有不同的答案。一切都很好。
The reason is: in my experience there are at least two different problems that prevent debugging on a real watch. Both require a different strategy.
原因是:根据我的经验,至少有两个不同的问题会阻止在真正的手表上进行调试。两者都需要不同的策略。
This answer tries to help you to decide when to use which strategy.
这个答案试图帮助您决定何时使用哪种策略。
- XCode installs, tells you it is running for a short time and then stops showing "running...".
- start with the answer of BalestraPatrick:
- restart your devices.
- Do not forget to restart your iPhone. This did the trick the first time I had this problem.
- XCode installs, tells you it is running for a longer period of time: "running <projectName> on Apple Watch of <yourname>.
- start with the answer of Jay Hickey or Andrei Herford
- starting the watch app manually probably does the trick.
- XCode 安装,告诉您它正在运行一小段时间,然后停止显示“正在运行...”。
- 从 BalestraPatrick 的回答开始:
- 重新启动您的设备。
- 不要忘记重新启动您的 iPhone。这是我第一次遇到这个问题时的伎俩。
- XCode 安装,告诉你它运行了更长的时间:“在 <yourname> 的 Apple Watch 上运行 <projectName>。
- 从 Jay Hickey 或 Andrei Herford 的回答开始
- 手动启动手表应用程序可能会成功。
I also had times when XCode was able to start my watch app without any help from me.
我也有过 XCode 能够在没有我任何帮助的情况下启动我的手表应用程序的情况。
Bonus:
奖金:
Starting with XCode 7.1 it seems XCode doesn't always compile all necessary Swift files (more often than before). This is not watch specific, it also applies to iOS apps. The symptoms can look similar to those of this question. -> clean your project and then restart XCode.
从 XCode 7.1 开始,XCode 似乎并不总是编译所有必需的 Swift 文件(比以前更频繁)。这不是特定于手表的,它也适用于 iOS 应用程序。症状可能与此问题的症状相似。-> 清理您的项目,然后重新启动 XCode。