I'm creating an app for creating alarms. If the app isn't in background or inactive everything work fine. But if the app is inactive (because i've pressed home button or i've pressed the lock button) when the notification occurs, after sliding or touching the banner, the code isn't executed and the app doesn't complete its actions.
I've read a lot of topics here and on the web but nothing can help me. Documentation says:
In iOS, you can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
if(UIApplication.sharedApplication().applicationState == UIApplicationState.Active)
println("Notification recieved and handled when inactive")
1 . when your app is not running, only
applicationDidFinishLaunching is called.
(either never was or was killed)
In that case, the launchOptions
NSDictionary contain the
2 . if it is running -regardless of the state-
didReceiveLocalNotification is called
In that case, use
UIApplication.sharedApplication().applicationState to see where your app is