in app delegate trying setup localnotification actionhandler perform segue , send notification destination viewcontroller trigger function in class, somewhere along line notification isn't being posted or received properly.
it's worth noting destination view controller has not being innitatited @ point.
here code currently: snippet appdelegate:
func application(application: uiapplication, handleactionwithidentifier identifier: string?, forlocalnotification notification: uilocalnotification, completionhandler: () -> void) { if identifier == "mainaction" { self.window?.makekeyandvisible() self.window?.rootviewcontroller?.navigationcontroller?.poptorootviewcontrolleranimated(true) (self.window?.rootviewcontroller as? uinavigationcontroller)?.viewcontrollers.first?.performseguewithidentifier("segue", sender: self) nsnotificationcenter.defaultcenter().postnotificationname("nc_seguedidperform", object: nil) }
and here in receiving view controller:
override func viewdidload() { super.viewdidload() nsnotificationcenter.defaultcenter().addobserverforname("nc_seguedidperform", object: nil, queue: nil, usingblock: ({ (notification: nsnotification!) in print ("working") })) }
i tried putting observer in viewwillapear , viewdidappear well, no avail. block not executed!
how make work can receive notification (or kind of 'signal' in destination view controller?
thanks in advance.
you doing wrong way. rightly pointed out calling performseguewithidentifier:
not guarantee view controller available notification fire next line not reach targeted view controller. suggested apple way implement prepareforsegue:
, pass data destination vc. method opportunity callee pass desired data destination vc.
override func prepareforsegue(segue: uistoryboardsegue!, sender: anyobject!) { if (segue.identifier == "segue") { // pass data next view } }
Comments
Post a Comment