Debug WatchKit on real Apple Watch - Nothing happens

前端 未结 4 1199
盖世英雄少女心
盖世英雄少女心 2020-12-23 22:22

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

相关标签:
4条回答
  • 2020-12-23 22:57

    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. 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.

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

    4. 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.
    5. 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.
    6. 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.

    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.

    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.

    To be able to attach the debugger I added a delay to the apps main function: [NSThread sleepForTimeInterval: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 :-)

    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.

    Happy testing with this awesome new Apple product :-P

    0 讨论(0)
  • 2020-12-23 23:04

    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.

    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.

    Now you can try to build and run the app from Xcode and it should work more reliably.

    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.

    0 讨论(0)
  • 2020-12-23 23:06

    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.

    1. 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.
    2. 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.

    I also had times when XCode was able to start my watch app without any help from me.

    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.

    0 讨论(0)
  • 2020-12-23 23:19

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

    1. Run the phone target in debug (on your actual iPhone of course)
    2. While the iPhone app is still running, switch to the watch target and run that in debug.
    3. 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.
    0 讨论(0)
提交回复
热议问题