objective-cwatchkitwkinterfacecontroller

Get visibile controller iWatch


I have this situation:

I have an iWatch app that has a root WKInterfaceController and when it fires a particular event I present another WKInterfaceController in this way:

WKInterfaceController * rootC = [WKExtension sharedExtension].rootInterfaceController;
[rootC presentControllerWithName:@"testController" context:nil];

My problem is that when it fires a particular event that I catch in InterfaceController, I have to show an alert in 'testController'. But from that root controller I can't get the visibile controller (like in iPhone project).


Solution

  • You can get visible controller by using WKExtension property:

    @property(nonatomic, readonly) WKInterfaceController *visibleInterfaceController;
    

    Source: https://developer.apple.com/documentation/watchkit/wkextension/2868459-visibleinterfacecontroller?language=objc