Some tasks, e.g. restoring an application’s data files from a backup should be performed while the application is not running to make sure there won’t be any concurrent access to the files. A desirable behaviour would be: Quit the application, perform the work and finally relaunch the application – just as Sparkle does when installing an update.
I’ve created a simple but well-working solution for that problem. My solution is using a small helper application which performes the work which has to be done while the main application is not running and relaunches it afterwards. You can download the sample project to try it out by yourself.
The RelaunchHelper is just an ordinary binary which has to be launched by your application just before it terminates itself. Of course, you can pass arguments to the RelaunchHelper. In the example project the path to the main application’s bundle is the sole argument. After invoking the helper, your application should terminate itself and let te helper take over.
I let the helper app sleep for a few seconds befor it relaunches the application to ensure, all files opened by the main application (in this example this is not an issue) are properly closed.
These are the steps you have to follow to create a project:
So, that’s my solution to the relaunch issue. Maye it’s not the most elegant way to do this. If you have a better solution, let me know. I really appreciate any comment.
Update:
A much better way to implement a relaunch helper has been provided by Cédric Luthi in his Blog post.
Please check it out.
Have you tried this in XCode 3.2? 3.2 can import your example project just fine, however adding the executable to the Copy Files phase does not seem to be possible anymore.
No, I haven’t tried it yet. Thanks for pointing me at this. I will check it out as soon as I can find some time.
if you have a better solution let me know💜
😀 That french guy has a better solution