Detecting active controller interface in WatchKit app?

I've created a WatchKit app with a hierarchical structure that can receive valid push notifications. When a notification arrives, the action is to click on one specific interface controller so that the user can view it right away without scrolling through the menu.

Apple's documentation in handleActionWithIdentifier:ForRemoteNotification:

states that this method is called only at the initial interface controller, so my code to handle remote notification source interface controller is as follows:

override func handleActionWithIdentifier(identifier: String?, forRemoteNotification remoteNotification: [NSObject : AnyObject]) {
    if let notificationIdentifier = identifier {
        if notificationIdentifier == "myActionIdentifier" {
            pushControllerWithName("myActionController", context: nil)
        }
    }
}

      

However, the problem is that the user has previously viewed this myActionController and then paused my application, and then this notification comes and the action will be taken, the application will push the same myActionController onto the stack again. Then, when the user clicks the back button, they simply appear on the previous myActionController, which will look the same. This issue also flocks - if the user receives multiple notifications of this type and takes action on all of them, myActionController will only start to fold.

I would like to fix this problem in handleActionWithIdentifier:ForRemoteNotification:

by checking what the currently active interface controller is and if it is already myActionController then do nothing (because it will reload once when willActivate:

called on it anyway). I know this is possible (sometimes) in iOS, for example in UINavigationController, but I don't know if it is possible in WatchKit. Does anyone have any idea?

+3


source to share


1 answer


I have almost the same scenario in my own WatchKit app, and I handled it by keeping track of which view controller is currently presented. In the simple version, you can keep track of the name of the last view controller you presented and clear it in the controller's view. The Activate method (how it will be called when the view controller is re-rendered). If you get your notification when something is submitted, you can decide if you need to fire / release the controller first.



This may be more than what you want / need, but I wrote a subclass JBInterfaceController

that wraps a lot of this functionality: https://github.com/mikeswanson/JBInterfaceController

+2


source







All Articles