Call function when Notification Center is dismissed


I am just coding my first iOS app using a today widget (using Swift). I was wondering if there is a function that is called whenever my app comes back to the foreground after dismissing the notification center.

I know I can use an Observer to check for UIApplicationWillEnterForegroundNotification but my function does not get called when pulling down the notification center while using my app and dismissing it again.

My problem is simple: It is quite unlikely users will pull down the notification center to manipulate data I am using in the app, but I still have to consider what happens if they do. The user is supposed to be able to save his current location by pressing the today widget button.

If that happens while using my app, the app won't check for new data.


I used the following code for determining if the notification center was opened during the application's run time:

#import "ViewController.h" @interface ViewController () @end @implementation ViewController { BOOL notificationCenterCurrentlyDisplayed; } - (void) viewDidLoad { [super viewDidLoad]; notificationCenterCurrentlyDisplayed = false; NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; [defaultCenter addObserver:self selector:@selector(onNotificationCenterDisplayed) name:UIApplicationWillResignActiveNotification object:nil]; [defaultCenter addObserver:self selector:@selector(onNotificationCenterDismissed) name:UIApplicationDidBecomeActiveNotification object:nil]; } - (void) onNotificationCenterDisplayed { notificationCenterCurrentlyDisplayed = true; NSLog(@"Notification center has been displayed!"); } - (void) onNotificationCenterDismissed { // Reason for this check is because once the app is launched the UIApplucationDidBecomeActiveNotification is called. if (notificationCenterCurrentlyDisplayed) { notificationCenterCurrentlyDisplayed = false; NSLog(@"Notification center has been dismissed!"); } } @end

Also the notification center was displayed method will also be called when the user decides to close the application into the background.


  • switch statement: “a constant value is expected”
  • Word Base/Stem Dictionary
  • iOS check if torch is on
  • How to write Delphi ActiveX control which can be used in MS Word/Excel/Powerpoint?
  • Can I customize a Jackson ObjectMapper by adding a module?
  • C Program Compiled with Cygwin and Called from Python Hangs
  • How do you create a Fuseki SPARQL server using the Apache Jena Java API?
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • extjs4 catching the scroll event on panel
  • How can Delete be both a DDL and a DML statement
  • C#: Import/Export Settings into/from a File
  • there is no graph with tensorboard
  • jQuery: add elements until a particular height is reached
  • Unable to install Git-core+svn by MacPorts
  • How can I set a binding to a Combox in a UserControl?
  • Inline R code in YAML for rmarkdown doesn't run
  • Django simple Captcha “No module named fields” error
  • AJAX Html Editor Extender upload image appearing blank
  • Word Open XML Mail Merge
  • Could not find rake using whenever rails
  • C++ Partial template specialization - design simplification
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Window Size for Mac application
  • Cassandra Data Model
  • Join two tables and save into third-sql
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • How to model a transition system with SPIN
  • ORA-29908: missing primary invocation for ancillary operator
  • How do I rollback to a specific git commit
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • embed rChart in Markdown
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Converting MP3 duration time
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF