WatchOS5 - how to debug an apple watch app? - debugging

I'm brand new to watchOS development - have my first app and extension. I have the following questions:
Are breakpoints available for watch OS extensions and apps? I set them, but they don't seem to trigger
Does the app fail to appear on the watch if there's a fatal crash during launch? It seems when I make a mistake, the app simply fails to install and I get almost no info in console and no stack trace of any kind.
How do I debug a WatchOS5 app is there some option I need to enable on device or XCode?

You can select watch complication or extension from the list of schemes in the run menu and run the app on watch and device. I was running the test app only.
The bad news is that the process times out on my old Macbook air when trying to run on device. And the watch Simulator is terribly slow, working at about 2 FPS.

Related

Can't find a way to properly debug nativescript application

I am having trouble finding a workable solution for debugging nativescript applications. I have tried the following options:
a) tns debug
This starts a tool called 'Nativescript Inspector'. It is painfully slow and to add insult to injury: it crashes more than it runs. I have not been able to it to run long enough to find even basic problems. It's perfectly useless to me.
b) tns debug --chrome
The chrome debugger is a lot better, but it seems impossible to simply reload. Every time you restart, you need to re-attach a fresh instance. Since this option works by copy & paste of a link, it becomes fairly cumbersome. Additionally, it does not really respect breakpoints properly, especially during app restarts! So ultimately, this is also useless.
c) Sidekick
This is supposed to be one of the prescribed methods of debugging. Half the time the debugger does not start. If it does, there is no way to break the flow during application start-up. Since I'm in the process of debugging parts that happen during start-up, I do never get a chance to set a breakpoint, barring tricks like wrapping the bootstrapping phase into a timer (which also costs time). So even this method is not working.
Do I really, really need to get Visual Studio? I really would like to avoid that ...
To debug the Views, currently, the best option is to use the debugger that comes with Sidekick.
If you want to debug the logic, however, the best option is to use the NativeScript extension for VS Code, and debug directly from VS Code. :)
Hope this helps.
https://marketplace.visualstudio.com/items?itemName=Telerik.nativescript
Debugging code that executes at start up is tricky, so you need to place debugger statements in your code, and start a debugging session with --debug-brk
tns debug ios --chrome --debug-brk
For more information, check the Debugger section in the Chrome DevTools docs - https://docs.nativescript.org/tooling/chrome-devtools#debugger
I´m starting with native script and I found that debugging is one of the biggest challenges.
My first approach was the native script extensión for Visual Studio Code, but it resulted a little bit unstable and Visual Studio Code lacks some features that I use a lot in webstorm.
Probably in a near future VEC + tns extension will be the choice, but right now my debugging strategy is:
1 Launch simulator
I'm using Osx and I want to debug in an Ipad simulator. By default the IOS simulator boots an Iphone X device. First I need to launch the simualtor with a custom device.
$ xcrun simctl list devices
== Devices ==
-- iOS 11.2 --
iPhone 5s (E3B6EA43-C805-49C2-9502-A44A465D8DF2) (Shutdown)
iPhone 6 (801E9E11-CA86-473A-9879-4B0742B827FB) (Shutdown)
iPhone 6 Plus (24013349-1A6F-489C-9A68-ABB00EBB4BBF) (Shutdown)
iPhone 6s (1A594D75-146C-4BEA-A250-1FADE7886114) (Shutdown)
Then I launch the simulator app specifying a device with the -CurrentDeviceUDID option
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <DEVICE-UDID>
NOTE: replace the with a valid UDID from the list.
More info at Xcode 6 - Launch simulator from command line
2. Use nativescript-cli commands
To get a list of available devices
# tns devices
To debug in a specific device:
# tns debug ios --device <device identifier>
Note: replace the device identifier with a valid id.
If you want to debug in an emulator
# tns debug ios --emulator
You have to find the url in the command output and open in chrome:
...
...
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/#02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:41000
....
More information about dedugging commands can be found in
https://docs.nativescript.org/tooling/debugging
More information about debugging with chrome-dev-tools
https://docs.nativescript.org/tooling/chrome-devtools#debugger
04/20/2018 Update
I´m developing in Mac OS X and with the new native-script cli 4.0 the debugging experience with the WebKit Web Inspector has improved. So I´m now using it for debugging:
tns debug ios --inspector

Debugging Apple Watch and iOS app simultaneously

Up until today, I've been able to build, run, and debug my watch app and iOS app at the same time. When I build and run, the debugger attaches to the watch automatically. Then I have to manually attach the iOS debugger. I have been following these steps and they always worked perfectly. I can hit breakpoints on both on the watch and the phone (which is what I need to do to be able to debug things like sendMessage or applicationContext).
The problem now is that when I go to attach the iOS app to the debugger manually (via Debug -> Attach to Process), it doesn't show up in the likely targets or in applications at all, even though the app is running on the phone.
I checked my schemes and made sure that the targets were still correct- they are.
I even tried Debug -> Attach to Process with PID or Name. When I try to attach the iOS app by name, I get an error saying Will install Watch App called with bad bundle identifier '(null).
Why is my iOS app no longer a likely target? How can I get it to attach to the debugger again while my watch app is also attached?
I use another way to debug on watch app and iPhone app at the same time. I run this script when watch and iPhone simulators are running on my Mac. Then launch my watch app or iPhone app on the same simulators. I can observe both log at the same time.
P.S. These log are come from console, so you should use NSLog(), not print().

Xcode Run Apple Watch target results in Finished running app on Watch

I am trying to debug my watch app. I build and try to run as usual. It says Build succeeded, installing to watch etc. but then, instead of launching my app, it says Finished running app on watch. I've restarted Xcode, reinstalled my app on watch etc. but no avail.
What am I doing wrong?
I've also restarted my Mac, my iPhone and my Watch. It then worked.
I restarted everything and it still didn't work. However, after the restart when I first run the app I received an error: Device doesn’t support wireless sync. With this, after disabling the wifi on the watch, things went back to normal.
From my experience, restarting all devices (iPhone, watch, and mac) sometimes allows the app to build on the watch, but it is very frustrating and a long process for a "maybe."
Especially when I get the Device doesn't support wireless sync. the most consistent solve has been disabling wifi on both the watch and the iPhone. Also, have the iPhone connected directly to the computer with a genuine cord.
Good luck.
Also, if you were using the simulator, stop it and quit the simulator before trying to compile to the real device.
You just have to attach the Xcode debugger to the process which is running on the watch!
Xcode -> Debug -> Attach to Process > "name of your app watch extension"
After that Xcode displays "Running ... Extension on Apple Watch" and you can start debugging

Proper way to debug watchos2 app in XCode7

I'm rewriting my watch app to work in watchos2 but have problems debugging on the actual watch (XCode7). What is the correct way how to do this?
1) Obvious (but naive) approach - connect your phone with paired watch, in XCode select Extension scheme to run on Phone + Watch. Click play and it should work, right? This seems to work only just after fresh pairing and breaks very quickly (after few debug runs). See issues and behaviour below
2) Run phone app first then add run of extension - this approach worked for me longer but eventually broke as well.
3) Unpair and pair again - more than painful experience, time consuming and not practical at all. Will help for a while though.
Main problems:
phone app not communicating - I've seen not reachable or messages just time out
watch app stops running - XCode is saying it's running but it's not - won't even attach. If I run it manually on watch most of the times it will attach but then the phone app is not reachable
watch app won't even install - I suspect when the XCode is saying it's running it in fact it doesn't because when I remove the app from watch and then run XCode goes through the whole install process and "running" but the icon doesn't even appear on the main screen
phone stops reacting when I use option 2) and try to run something else while app is attached
phone seems to be blocked, selecting other apps (even going back to my app) won't work until I kill the session
Setup: The phone and watch is paired correctly, phone can see watch, watch can see phone, other apps are working. Watch "trusts" the computer as well, app is "shown on apple watch". Phone is 5s 9.0.1.
I've tried various restart combinations (phone|watch|xcode|mac), shuffled cables, disconnect, reconnect, etc. but that didn't help either.
Did anybody find a usable way how to debug watchos2 app from XCode? Nobody else seems to be complaining about this with released XCode7 though I've seen lots of similar issues in beta builds.
Use Apple watch recharging cable, connect your watch to developing Mac that runs Xcode.
It provides much more successful and fast debugging.
I have been dealing with the same issue this last days, I just updated to iOS 9.2, watchOS 2.1 and XCode 7.2, and now everything works.
After update XCode to 7.2, iOS9.2 my phone and WatchOS2.1 my Apple Watch the debug process is better. I suggest to update all your devices.

How to solve this error in Xcode when testing your app on the Apple Watch

I've tested my Apple Watch app on the simulator and it runs perfectly...However I couldn't test my app on the actual Apple Watch device:
I ran my iPhone app in Xcode.... Once completed it will install the app on Apple Watch.
Then, Apple watch app will launch and stuck on launching screen with "loading" spinner on the Apple Watch device.
The Apple watch will just close itself and this error will appear in Xcode:
You need to run the your iphone app scheme not the watchapp or extension scheme, once you will installed your iOS application on your device with watch kit support.
After installing the iPhone, you need to check your watch, application will automatically installed on Watch. If still you are not able to see the application then you need to visit application "Apple Watch" and scroll down to see your application and turn on apple watch support for your application.
If you are running the Watch OS2 app then after deploying the app on the Watch, you will need to reboot the Watch. Once rebooted, the Watch app will now run and not stuck anymore, loading time is about a few seconds only.

Resources