Checking if iOS app was launched from local notification? -


how detect if app not in active, inactive, or background state (terminated) launched local notification? far, i've tried 2 methods in app delegate's didfinishlaunchingwithoptions:

func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {     // method 1:     if let options = launchoptions {         if let key = options[uiapplicationlaunchoptionslocalnotificationkey] {             notificationcenter.postnotification(nsnotification(name: "applicationlaunchedfromnotification", object: nil))         }     }      // method 2:     let notification = launchoptions?[uiapplicationlaunchoptionslocalnotificationkey] as! uilocalnotification!     if (notification != nil) {         notificationcenter.postnotification(nsnotification(name: "applicationlaunchedfromnotification", object: nil))     }      return true } 

in view controller, observe notification in viewdidload , in response, set uilabel's text:

override func viewdidload() {     super.viewdidload()     notificationcenter.addobserver(self, selector: "handleapplaunchfromnotification", name: "applicationlaunchedfromnotification", object: nil) }  func handleapplaunchfromnotification() {     debuglabel.text = "app launched notification" } 

but uilabel's text never set after launching terminated app local notification.

my questions are:

  1. what doing wrong?
  2. is there easier way debug situation other setting uilabel? once app terminated, xcode's debugger detaches app , can't use print().

you checking local notification in didfinishlaunchingwithoptions methods contains launchoptions remote notifications. if app in terminated state , perform action on local notification didreceivelocalnotification gets call after didfinishlaunchingwithoptions method.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -