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 !!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…