Block thread at applicationWillTerminate: won't get killed in a short time, but WILL be rejected by App Store. For non-AppStore or personal applications, here is code:
@interface MyApplication : UIApplication
{
BOOL _isApplicationSupposedToTerminate;
}
@property (assign) BOOL isApplicationSupposedToTerminate;
- (void)_terminateWithStatus:(int)status;
@end
@implementation MyApplication
@synthesize isApplicationSupposedToTerminate = _isApplicationSupposedToTerminate;
- (void)_terminateWithStatus:(int)status
{
if (self.isApplicationSupposedToTerminate) {
[super _terminateWithStatus:status];
}
else {
return;
}
}
@end
In main.m
int retVal = UIApplicationMain(argc, argv, @"MyApplication", nil);
Delegate:
- (void)applicationWillTerminate:(UIApplication *)application
{
[(MyApplication*)application setIsApplicationSupposedToTerminate:!kIsTransferDone];
}
This will stop application from terminating unless your transfer is done. Setup a timer for check timeout is important. And in applicationDidReceiveMemoryWarning:, quit your app by:
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
[(MyApplication*)application setIsApplicationSupposedToTerminate:YES];
[application terminateWithSuccess];
}
This should be able to make you finish your job. For jailbroken only.