On Fri, Feb 6, 2009 at 8:06 AM, slasktrattena...@gmail.com
<slasktrattena...@gmail.com> wrote:
> You don't need a helper app for this.
>
> - (void) relaunch
> {
>        int processIdentifier = [[NSProcessInfo processInfo] 
> processIdentifier];
>        NSString *myPath = [NSString stringWithFormat:@"%s",
>        [[[NSBundle mainBundle] executablePath] fileSystemRepresentation]];
>        [NSTask launchedTaskWithLaunchPath:myPath arguments:[NSArray
> arrayWithObject:[NSString stringWithFormat:@"%d",
> processIdentifier]]];
>        [NSApp terminate:self];
> }

If the user has added your application to the Dock permanently, this
will create a new instance of the application with a second icon, then
quit the first, without merging them. The result: one icon for a
non-running application, and a second icon for a running application.
Not good.

My preferred approach is to create a very small tool like this:

int main(int argc, char **argv) {
    char dummy;
    read(STDIN_FILENO, &dummy, 1);
    CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL,
argv[1], strlen(argv[1]), 0);
    LSOpenCFURLRef(url, NULL);
    return 0;
}

You can then launch it from the parent application, passing the path
to your .app as the only parameter, and giving it an NSPipe for
standard input. When you quit, the pipe closes and the read()
unblocks. It then relaunches your application using LaunchServices,
and you're back in business.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to