• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Quit helper app when main app terminates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quit helper app when main app terminates


  • Subject: Re: Quit helper app when main app terminates
  • From: Robert Martin <email@hidden>
  • Date: Thu, 12 Jul 2012 13:27:34 -0400

The best way? I have no idea… This is what I do, and it works.

I store the path to my helper app in 'path', and do the following when my app is about to quit:


//---------------------------------------------------------------------
- (void)applicationWillTerminate:(NSNotification *)aNotification
//---------------------------------------------------------------------
{
	[super applicationWillTerminate:aNotification];

	AppleEvent tAppleEvent, tReply;
	AEBuildError tAEBuildError;
	ProcessSerialNumber currentProcessPSN;
	NSNumber *psnHi = nil;
	NSNumber *psnLo = nil;

	NSArray * runningApps = [[NSWorkspace sharedWorkspace] launchedApplications];

	for(NSDictionary * appInfo in runningApps){
		if( [path isEqualToString:[appInfo objectForKey:@"NSApplicationPath"]] ){
			psnHi = [appInfo objectForKey:@"NSApplicationProcessSerialNumberHigh"];
			psnLo = [appInfo objectForKey:@"NSApplicationProcessSerialNumberLow"];
			break;
		}
	}

	if(psnHi == nil) return;

	currentProcessPSN.highLongOfPSN = [psnHi unsignedIntegerValue];
	currentProcessPSN.lowLongOfPSN = [psnLo unsignedIntegerValue];

	OSStatus result = AEBuildAppleEvent( kCoreEventClass, kAEQuitApplication, typeProcessSerialNumber, &currentProcessPSN,
										sizeof(ProcessSerialNumber), kAutoGenerateReturnID, kAnyTransactionID, &tAppleEvent, &tAEBuildError,"");
	result = AESend( &tAppleEvent, &tReply, kAEAlwaysInteract+kAENoReply, kAENormalPriority, kNoTimeOut, nil, nil );
}


--Rob


On Jul 12, 2012, at 12:33 PM, Jerry Krinock <email@hidden> wrote:

> What is the best way to make a helper app quit when the associated main app quits (or crashes)?  No harm will be done if it keeps running for a minute or so.
>
> Thanks,
>
> Jerry Krinock


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Quit helper app when main app terminates
      • From: Mark Munz <email@hidden>
    • Re: Quit helper app when main app terminates
      • From: Matt Patenaude <email@hidden>
References: 
 >Quit helper app when main app terminates (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Quit helper app when main app terminates
  • Next by Date: Re: Quit helper app when main app terminates
  • Previous by thread: Quit helper app when main app terminates
  • Next by thread: Re: Quit helper app when main app terminates
  • Index(es):
    • Date
    • Thread