Reputation: 886
I am saving some documents (images and PDF's) in my app to the iPad directory. Now these documents being customer sensitive need to be removed once the operation is done , user logs off. I am handling the removal from directory in case of Log off event , but how to achieve this in case the app crashes abruptly.
Upvotes: 4
Views: 710
Reputation: 1364
I have some code in my app that writes log in case of crash. May be you can use also to perform some actions before the process is gone.
Here it is:
@interface AppDelegate()
void uncaughtExceptionHandler(NSException *exception);
@end
@implementation AppDelegate
void uncaughtExceptionHandler(NSException *exception)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"app_did_crash"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(BOOL)application:(UIApplication *)application
{
// Get crash log
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}
Upvotes: 1
Reputation: 21
I think you will need an exception handler using NSSetUncaughtExceptionHandler
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSSetUncaughtExceptionHandler(&myExceptionHandler);
}
void myExceptionHandler(NSException *exception)
{
// do something before app crash here
}
Upvotes: 0
Reputation: 8954
You need to add an UncaughtExceptionHandler, and delete caches.
void myHandler(NSException *exception)
{
// Remove caches...
.....
// And maybe let the app to crash?
exit(0);
}
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&myHandler);
....
}
so myHandler will be called when unhandled NSException is raised
Upvotes: 5