0

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]; 
Justin Williams
  • 703
  • 1
  • 9
  • 26
  • You get “launch path not accessible” because “/usr/bin/arch -i386 -ppc /Applications/YourApp.app/Contents/MacOS/YourApp” is not a path of an executable file on your system. NSTask does not use the shell; you need to pass it the path of the executable you want to run (/usr/bin/arch) and the list of arguments *separately*, with the arguments also separate from each other, collected in an NSArray. – Peter Hosey Feb 03 '10 at 06:37

3 Answers3

2

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

Yuji
  • 34,103
  • 3
  • 70
  • 88
0

try this code for relaunch your app:

//terminate your app in some of your method:
[[NSApplication sharedApplication]terminate:nil];

- (void)applicationWillTerminate:(NSNotification *)notification {

    if (i need to restart my app) {

       NSTask *task = [NSTask new];
       [task setLaunchPath:@"/usr/bin/open"];
       [task setArguments:[NSArray arrayWithObjects:@"/Applications/MyApp.app", nil]];
       [task launch];
   }
}
Vitaliy
  • 64
  • 6
0

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

Victor
  • 1