tags:

views:

3000

answers:

8

Hi

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  A: 

iPhone OS doesn't allow you to add background processes.

Rudi
This 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
+2  A: 

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.

Mark Bessey
+6  A: 

What's more likely is, On Exit, they save state, then on Launch resume they transfer.

Jordan
A: 

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.

Mike Chen
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
Doing anything in applicationWillTerminate: that might take significant time is a bad idea.
Mark Bessey
+2  A: 

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.

Mike Chen
Nice 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: <app> failed to terminate in time.<br>
TumbleCow
A: 

I have heard that there are some apps that hook into the Apple processes that will run in the background (namely, hooking into the Apple clock timer API), which will allow some non-UI background process on your 3rd party app to continue to run. Is this legitimate? Supposedly, there are some GPS-tracker apps that are using this and have passed Apple review and are for sale in the app store.

Any ideas?

A: 

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.

RRB
A: 

have you save the problem? if yes,could you help me please?

maxpy