endemic
endemic

Reputation: 1366

watchOS 3 app restarts after tapping complication

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?

Upvotes: 2

Views: 285

Answers (2)

Jonny
Jonny

Reputation: 2084

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.

Upvotes: 0

John Pollard
John Pollard

Reputation: 450

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

Upvotes: 0

Related Questions