I think that you cannot find out when your local notification is sent, mainly because you can schedule a local notification or send it right away if your application is in the background.
According to Apple :
You schedule a local notification by calling scheduleLocalNotification: The application uses the fire date specified in the UILocalNotification object at the time of delivery. Alternatively, you can immediately send a notification by calling the presentLocalNotificationNow: method.
Applications may also find that local notifications are useful when they run in the background, as well as some messages, data, or other items that may be of interest to the user. In this case, the application can immediately send a notification using the UIApplication presentLocalNotificationNow: method (iOS gives a limited time to run in the background).
It is not possible to know when the UILocalNotification was sent, but when it was received, this is of course the case. In your case, I assume that you are planning UILocalNotification , so share it in parts:
A notification is delivered when the application is not open and the user touches it
The delegate for the iOS application implements the application:didFinishLaunchingWithOptions: method to handle local notification. It obtains the associated UILocalNotification object from the startup parameter dictionary using the UIApplicationLaunchOptionsLocalNotificationKey key. Therefore, you can find out where the application was opened by touching UILocalNotification . See the following code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { if let launchNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
A notification is delivered when the application is launched and the user touches it
Once the user touches UILocalNotification , you can process it using the didReceiveLocalNotification method and do whatever you want inside it.
A notification is delivered when the application is running and the user does not touch it
If the user does not touch UILocalNotification , the only thing you can do to find out if your UILocalNotification been sent is to save the list with UILocalNotifications that you planned earlier and check it later (this is not a great solution, but its work).
However, there is always a UIApplicationWillEnterForegroundNotification that can be used to notify the UIViewController that you want to update so that the application comes to the forefront, as described below:
private var foregroundNotification: NSObjectProtocol! override func viewDidLoad() { super.viewDidLoad() foregroundNotification = NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationWillEnterForegroundNotification, object: nil, queue: NSOperationQueue.mainQueue()) { [unowned self] notification in print("Notified ViewControllerB") } } deinit {
I think that you need to think correctly what you need to do inside your application when your notification is received in case the user does not touch it.
Hope this helps you.