2

I have a simple "timer" watchOS app that uses hierarchical navigation. I can press the digital crown to return to the watch Springboard, then tap the app icon and be returned to the same interface controller I was using.

If I return to the watch face and tap my app's complication, the app is launched, but appears to have restarted: I lose my current state. Is there any way to prevent this?

2 Answers 2

0

It sounds like you're asking how to stop your app being swapped out of memory?

If so, just like on iOS this isn't possible - and obviously the watch has less memory than a phone so is more likely to be swapped out.

What you need to do is store your state in some persistence layer - e.g. NSUserDefaults - so when the app restarts it can reload its state

3
  • No, the app is still in memory. Tapping the app icon causes the app to resume. Tapping the complication restarts it. I see a brief flash of the previous (in-memory) state of my app, and then it loads the root interface controller.
    – endemic
    Oct 31, 2016 at 15:55
  • However, your suggestion about UserDefaults is a good one. I'll probably end up implementing that.
    – endemic
    Oct 31, 2016 at 15:57
  • The 'flash' is probably the snapshot the system has taken of the screen in it's previous state. The watch is very slow of course (compared to phones) so you can often 'see the join' between the snapshot and the app reloading Nov 1, 2016 at 9:17
0

If you open your watch app by tap complication, the app will automatically back to root interface controller(s). This is a system forced behavior.

If you want to preserve previous state, you need to change your app's hierarchic to page-based interfaces.

User interaction in page-based interfaces can be just like navigation-based interfaces. You can replace pushController(withName:context:), pop() and popToRootController() methods to becomeCurrentPage(). I also found switch from one page interface to another is also faster than navigation (push/pop) to another.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.