ios - Detect active interface controller in WatchKit app? -


i've built watchkit app hierarchical structure can receive actionable push notifications. when notification comes in, action push 1 particular interface controller user can view without having drill down through menus.

apple's documentation on handleactionwithidentifier:forremotenotification: states method called on initial interface controller, code handling remote notification in initial interface controller looks this:

override func handleactionwithidentifier(identifier: string?, forremotenotification remotenotification: [nsobject : anyobject]) {     if let notificationidentifier = identifier {         if notificationidentifier == "myactionidentifier" {             pushcontrollerwithname("myactioncontroller", context: nil)         }     } } 

however, problem is, if user viewing myactioncontroller , had suspended app, , later notification comes in , action taken, app push same myactioncontroller onto stack again. when user taps "back" button, they'll pop onto previous myactioncontroller, same. problem stacks, - if user receives multiple notifications of type , takes action on of them, myactioncontroller start stacking up.

i'd remedy problem in handleactionwithidentifier:forremotenotification: checking current active interface controller is, , if it's myactioncontroller, don't (because reload once willactivate: called on anyway). know possible (sometimes) in ios, example on uinavigationcontroller, don't know if possible in watchkit. have ideas?

i have exact same scenario in own watchkit app, , i've handled tracking view controller being presented. in simple version, track name of last view controller you've presented , clear in presenting controller's willactivate method (as called when presenting controller re-displayed). if received notification while presented, can decide if need dismiss/pop controller first.

it might more want/need, i've written jbinterfacecontroller subclass wraps lot of functionality: https://github.com/mikeswanson/jbinterfacecontroller


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -