Debug WatchKit在真正的苹果手表 - 没有什么发生 [英] Debug WatchKit on real Apple Watch - Nothing happens

查看:115
本文介绍了Debug WatchKit在真正的苹果手表 - 没有什么发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调试我的WatchKit扩展/应用程序在一个真正的苹果手表。使用模拟器调试iPhone应用程序和WatchKit扩展模拟器没有问题:

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:


  1. 选择WatchKit App Profile并在Simulator = => App在Watch模拟器中启动,我可以使用扩展代码中的断点进行调试。

  2. 要调试iPhone应用程序以及启动应用程序在模拟器中并手动附加调试器==>我可以使用 iPhone代码中的断点进行调试。

  1. Select the WatchKit App Profile and run in Simulator ==> App is launched on in Watch Simulator and I can use breakpoints in the Extension code to debug.
  2. 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 Code to debug.

观察iPhone应用程序和手表应用程序的工作是没有问题的。至少不在模拟器中。

It is no problem to observe both the work of the iPhone app and the watch app. At least not in the simulator.

我想在真正的Apple Watch 上做同样的事情。但是当我选择WatchKit应用程序配置文件和我的真正的iPhone(而不是模拟器),点击运行没有发生任何事情。这意味着Xcode似乎建立和启动应用程序,但没有发生在设备上。 Xcode中的状态字段显示:

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:


构建MyApp WatchKit应用程序:MyApp WatchKit Extension

Building MyApp WatchKit App: MyApp WatchKit Extension

建立MyApp WatchKit应用程式:完成...

Building MyApp WatchKit App: Finishing...

在我的iPhone 6上运行MyApp

Running MyApp on My iPhone 6

这是所有。没有调试窗口,断点被忽略或不工作,该应用程序不会在iPhone或Apple Watch上启动。

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应用程序和WatchKit应用程序安装没有任何问题。当我点击手表上的应用程序图标,我可以开始并使用该应用程序。 问题是我无法调试此过程。

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应用程序尝试使用 openParentApplication:reply:联系iPhone应用程序时,当iPhone应用程序尚未运行时会发生什么?这在模拟器中完美工作,但在真实设备上的Watch Apps似乎没有从iPhone应用程序的回复,只是等待永远。

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应用程序,看看代码如何执行我不能确定发生了什么...

I already found hints to 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...

推荐答案

感谢您的答案。我终于设法得到调试运行(大部分时间)在我真正的苹果手表。但是这是相当麻烦,不是很可靠。在评论中没有足够的空间,所以我将使用这个答案来描述我的解决方案。

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:


  1. 确保您的手表上的应用程序未运行(如BalestraPatrick所述)。启动应用程序并按住侧面按钮几秒钟,以打开关闭手表对话框。按住侧面按钮几秒钟即可关闭应用程式,并返回Watch主画面。

  2. 确保iPhone未锁定。

  1. 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.
  2. Make sure the iPhone is not locked.

选择 WatchKit App 目标和您的真实iPhone并运行项目。

Select the WatchKit App target and your real iPhone and run the project.

在我的例子中,我发现要检查iPhone应用程序如何处理 application:handleWatchKitExtensionRequest:reply:在应用未激活之前调用。这很重要,因为这不能使用模拟器来完成。如果应用程序需要很长时间来处理请求,Watch将不会收到有效的响应。

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.

按照上述步骤操作后,Xcode仅附加在手表应用程序中,不会保存在iPhone应用程序代码中的断点上。为此,必须手动将调试器附加到iPhone应用程序进程,该程序在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.

为了能够附加调试器为应用程式主要功能新增延迟: [NSThread sleepForTimeInterval:5]

To be able to attach the debugger I added a delay to the apps main function: [NSThread sleepForTimeInterval:5]:


  1. 在Watch App中选择将启动对iPhone App的调用的函数

  2. iPhone应用程序将在后台启动。

  3. 选择 Debug \Attach To Process\Likely Targes \您的iPhone应用程式
  4. 5秒钟延迟后,程序将继续进行,您也可以在iPhone应用程式程式码中使用断点。

  5. 在完成测试后,请不要忘记删除延迟代码: - )

  1. Select function in Watch App that will start the call to the iPhone App
  2. The iPhone App will be launched in background. The delays gives you 5 seconds to attach the debugger.
  3. Choose Debug\Attach To Process\Likely Targes\Your iPhone Appin Xcode to attach the debugger.
  4. After the 5 seconds delay the process will continue and you will be able to use breakpoints in your iPhone app code as well.
  5. Do not forget do remove the delay code when you finished testing :-)

注意:
您将无法从iPhone应用程序看到 NSLog 输出(或任何控制台输出),因为附加调试器不会重新路由控制台输出。

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.

使用这个真棒新Apple产品快乐测试:-P

Happy testing with this awesome new Apple product :-P

这篇关于Debug WatchKit在真正的苹果手表 - 没有什么发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆