Local notification on application termination
iphone, uiapplicationdelegate, uilocalnotification
Solution
You will not receive any notice when it gets terminated, when your app is suspended in the background.
iOS will send a kill -9 signal for your apps progress and you app is just killed, this is the same thing that happens when the user kills your app from the quicklaunch tray.
From the Apple documentation:
Even if you develop your app using iOS SDK 4 and later, you must still be prepared for your app to be killed without any notification. The user can kill apps explicitly using the multitasking UI. In addition, if memory becomes constrained, the system might remove apps from memory to make more room. Suspended apps are not notified of termination but if your app is currently running in the background state (and not suspended), the system calls the applicationWillTerminate: method of your app delegate. Your app cannot request additional background execution time from this method.
Problem
I am working on an application which will not work if terminated. It has some background tasks. I want to show a local notification if the app is terminated. There are applications which do this which means this is doable. But I am not able to find out a way. I have tried to set up a local notification in applicationWillTerminate: method of appdelegate as well as added a notification of app termination in my viewcontroller but none of the methods get called when app is actually terminated. ``` - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"terminated"); UIApplication * app = [UIApplication sharedApplication]; NSDate *date = [[NSDate date] dateByAddingTimeInterval:15]; UILocalNotification *alarm = [[UILocalNotification alloc] init] ; if (alarm) { alarm.fireDate = [NSDate date]; alarm.timeZone = [NSTimeZone defaultTimeZone]; alarm.repeatInterval = 0; alarm.alertBody = @"This app does not work if terminated"; alarm.alertAction = @"Open"; [app scheduleLocalNotification:alarm]; } [app presentLocalNotificationNow:alarm]; // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } ``` Any help would be great. Thanks in Advance !!!