开发者

Relaunching application via NSTask ignores LSMinimumSystemVersionByArchitecture

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];    
[NSTas开发者_运维百科k launchedTaskWithLaunchPath:fullPath arguments:arg];
[NSApp terminate:self]; 


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


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


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];
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜