How to implement Daemon process for background task in iphone sdk 3.0? [closed]
Like qik.com or ustream.com , when they upload content from iphone to server , it works via daemon . So even when out of the app with exit , the task is still on with background daemon . Is there any method that I can implement daemon process in a same way ? Thanks !!!
Solution 1:
iPhone OS doesn't allow you to add background processes.
Solution 2:
What's more likely is, On Exit, they save state, then on Launch resume they transfer.
Solution 3:
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.