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 !!!
7 Answers
iPhone OS doesn't allow you to add background processes.

- 2,450
- 5
- 26
- 37
-
3This will change with iPhone OS 4.0. You can now request for OS to keep your app running for few more minutes, or register for some events (location change) to wake your app up. – Rudi May 05 '10 at 22:37
What's more likely is, On Exit, they save state, then on Launch resume they transfer.

- 21,746
- 10
- 51
- 63
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.

- 1,113
- 8
- 9
-
1Nice method, but it doesn't work very well for me. It just allows the application to live some 1 to 20 seconds longer, after which it will still get killed with a warning in the logs:
failed to terminate in time. – TinkerTank Oct 05 '10 at 20:46
Unfortunately, you can't create a background process using the iPhone SDK. You'll only be able to upload data while the app is running.

- 19,598
- 4
- 47
- 69
Deamon service is the best services rather than other services or concept for background processing in iphone. Please visit the the following link
http://chrisalvares.com/blog/?tag=iphone-daemon.

- 7,801
- 9
- 55
- 88
-
1`From Part I: "You will need to do the following things before we can get started. 1) Make sure your iPhone is jail broken"` - not very useful.... – jww Apr 01 '11 at 06:45
If the data has to be sent, I would wait until the transfer's done in applicationWillTernimate:. As far as I know, the application won't quit if you block the thread in applicationWillTerminate.(Correct me if I'm wrong). But be careful, if the data is huge or the user's internet speed sucks, you should quit anyway and resume the transfer next time. Set up a timer to check timeout is suggested.
Attention: This may be rejected by App Store.

- 1,113
- 8
- 9
-
Apple actually reserves the right to terminate the app if the thread blocks in `applicationWillTerminate:` for longer than a certain amount of time (generally about five seconds or so). Furthermore, if you block longer than that and the app *does* get killed, it loses the nice fade-out transition apps have when they quit normally; instead, it looks like a crash to the user (the app just disappears and the device presents the springboard again). – Tim Sep 12 '09 at 04:17
-
Doing anything in applicationWillTerminate: that might take significant time is a bad idea. – Mark Bessey Sep 12 '09 at 04:30