9

I updated my app for Apple Watch, but I should have weighed it too much and now it's definitely slow. I can't understand the reasons of this slowdown so I would like to debug app but I don't know how to do that because in the simulator app works normally, slowdowns manifest only on the device.

I tried running app directly from xCode on Watch but once xCode launched the installation of the app on the Watch, it stops the run so I can't see what happens while running (for instance when run certain breakpoint or otherwise do us debug).

Does anyone have an idea of what's the right way to debug on a physical Apple Watch?

P.S.: For instance, this code:

func clearScreen() {
    firstPicker.setSelectedItemIndex(0)
    secondPicker.setSelectedItemIndex(0)

    defaultLabels()
}

func defaultLabels() {
    feesLabel.setText(NSLocalizedString ("FEES", comment: "Commissioni"))

    clearAllMenuItems()
    addMenuItemWithItemIcon(.Decline, title: NSLocalizedString("CAN_CEL", comment: ""), action: "clearScreen")
    if DefaultParameter.sharedInstance.wishMode == true {
        addMenuItemWithImage(UIImage(named: "will")! , title: NSLocalizedString("WILL_RECEIVE", comment: ""), action: "willWishButtonPressed")
        receivedLabel.setText(NSLocalizedString ("DESIRED_AMOUNT", comment: ""))
    } else {
        addMenuItemWithImage(UIImage(named: "wish")! , title: NSLocalizedString("WISH_RECEIVE", comment: ""), action: "willWishButtonPressed")
        receivedLabel.setText(NSLocalizedString ("RECEIVED_AMOUNT", comment: ""))
    }
}

takes around 7 seconds to run...

Matte.Car
  • 2,007
  • 4
  • 23
  • 41

2 Answers2

16

I do not recommend trying to debug your Apple Watch app by pressing the Run button in Xcode. It is very unpredictable as to whether or not it will work. Here is how I debug on the Apple Watch and it works for me every time:

  1. Connect your iPhone to your computer running Xcode
  2. Run your app on your iPhone from Xcode
  3. Click the stop button in Xcode
  4. On your Apple Watch, make sure that the new app update has been transferred over (Note that if you didn't make any changes to the watch app, a new one doesn't seem to get copied over at the moment).
  5. Launch your watch app from your watch (no Xcode yet!)
  6. In Xcode select the Watch Extension from the schemes, make sure your device is selected from device list, should show your phone + your Apple Watch.
  7. In Xcode, click "Debug -> Attach to process" and pick your watch extension's process. Note that you will see a process for both your watch app and the watch extension. Make sure to pick the watch extension
  8. On your watch, tap on some UI element, such as a button.
  9. Your watch app will have a loading spinner appear in the middle of the screen. This spinner continues until the watch can connect to Xcode. Sometimes this take a few minutes (around 3 for me!). When the spinner stops then you should be able to debug in Xcode normally.

The only trick is to be patient when waiting for Xcode to connect in step 8. It is definitely slow to do, but gives you far more performance information that running on the simulator.

Vlad
  • 5,727
  • 3
  • 38
  • 59
lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • 3
    Under "Debug -> Attach to process" appears a blank menu, I think Apple have still lot of work to do... – Matte.Car Jan 13 '16 at 16:38
  • Is your iPhone plugged and unlocked? Xcode can only connect to the apple watch processes if the iPhone allows it, and to do so it needs to be connected to the computer running Xcode. – lehn0058 Jan 13 '16 at 16:40
  • This menu should show you all of the processes running on your iPhone and Apple watch (watch will be at the top) – lehn0058 Jan 13 '16 at 16:40
  • 4
    Yeah, I followed your guide step by step but nothing! Appears something like "Getting process list" (I can't read it exactly) just for a flash than all blank! Yesterday there was a list of processes but today nothing! I tried even restarting xCode, cleaning project but nothing! – Matte.Car Jan 13 '16 at 16:43
  • Have you tried restarting your iPhone? You should be able to see that list to attach to processes on the phone even without the watch. – lehn0058 Jan 13 '16 at 16:56
1

Sounds like a familiar watchOS bug for me, so I presume you didn't do anything wrong.

You should try to delete the watch app from your watch using the Watch app on your phone, then run it again.

You will definitely need some patience, so try it multiple times if it doesn't work. I had the experience that it worked after a few attempts.

fredpi
  • 8,414
  • 5
  • 41
  • 61
  • I've found this http://stackoverflow.com/questions/31741744/debug-watchkit-on-real-apple-watch-nothing-happens?rq=1 ...but it isn't a solution, it's a nightmare! – Matte.Car Jan 09 '16 at 18:00
  • Hmm seems to be not that straightforward. Another option I succeeded with was to launch the app on the watch, and then run it from Xcode. The app first crashed and then launched properly in my case. – fredpi Jan 09 '16 at 18:02
  • 1
    I tried even this but breakpoints keep not working, maybe works only sometimes... – Matte.Car Jan 09 '16 at 18:13