views:

221

answers:

2

I'm running into an issue with relaunching my application on 10.5. In my Info.plist I have LSMinimumSystemVersionByArchitecture set so that the application will run in 64-bit for x86_64 and 32-bit on i386, ppc, and ppc64.

I have a preference in the app that allows the user to switch between a Dock icon & NSStatusItem, and it prompts the user to relaunch the app once they change the setting using using the following code:

id fullPath = [[NSBundle mainBundle] executablePath];
NSArray *arg = [NSArray arrayWithObjects:nil];    
[NSTask launchedTaskWithLaunchPath:fullPath arguments:arg];
[NSApp terminate:self];

When this executes on 10.5, however it relaunches the application in 64-bit which is not a desired result for me. From what I gather reading the docs its because the LS* keys are not read when the app is launched via command line.

Is there a way around this? I tried doing something like below, which worked on 10.6, but on 10.5 it was chirping at me that the "launch path not accessible". ([NSApp isOnSnowLeopardOrBetter] is a category that checks the AppKit version number).

id path = [[NSBundle mainBundle] executablePath];    
NSString *fullPath = nil;
if (![NSApp isOnSnowLeopardOrBetter])      
  fullPath = [NSString stringWithFormat:@"/usr/bin/arch -i386 -ppc %@", path];
else    
  fullPath = path;

NSArray *arg = [NSArray arrayWithObjects:nil];    
[NSTask launchedTaskWithLaunchPath:fullPath arguments:arg];
[NSApp terminate:self]; 
+2  A: 

You should instead use the methods of NSWorkspace, which does take into account Info.plist keys. For example, use -(BOOL)launchApplication:(NSString*).

Yuji
A: 

It's because you use spaces inside fullpath, use arguments within an array [NSArray arrayWithObjects:@"/usr/bin/arch",@"-i386",@"-ppc",path,nil].

Victor