Reputation: 552
I've got watch connectivity setup in the Extension Delegate of my watch app and I'd like to push a controller when a certain method is called. However pushControllerWithName:context:
can't be called on the extension delegate.
Is there a way I could push a controller from the Extension Delegate?
Thanks a million
Upvotes: 4
Views: 2670
Reputation: 1
I found that adding the line below to get the root controller worked for me using Swift.
rootInterfaceController?.pushController(withName: "MapController", context: path)
Upvotes: 0
Reputation: 1448
As @dan has pointed out in the comments, you can get a reference to your root controller using [WKExtension sharedExtension].rootInterfaceController
. From there you can use pushControllerWithName:context:
to push a controller.
Upvotes: 3
Reputation: 109
You could inherit WKInterfaceController
and store the current controller in somewhere.
class BaseInterfaceController: WKInterfaceController {
...
override func willActivate() {
super.willActivate()
// store current controller with some weak reference
XXXManager.shareInstance().currentController = self
}
override func didDeactivate() {
super.didDeactivate()
if XXXManager.shareInstance().currentController == self {
XXXManager.shareInstance().currentController = nil
}
}
...
}
Upvotes: -1