0

我在 10.5 上重新启动我的应用程序时遇到了问题。在我的 Info.plist 中,我设置了 LSMinimumSystemVersionByArchitecture,以便应用程序在 x86_64 上以 64 位运行,在 i386、ppc 和 ppc64 上以 32 位运行。

我在应用程序中有一个首选项,允许用户在 Dock 图标和 NSStatusItem 之间切换,并且一旦用户使用以下代码更改设置,它就会提示用户重新启动应用程序:

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

但是,当它在 10.5 上执行时,它会以 64 位重新启动应用程序,这对我来说不是理想的结果。从我收集阅读文档的内容来看,因为当应用程序通过命令行启动时不会读取 LS* 键。

有没有解决的办法?我尝试做类似下面的事情,它在 10.6 上工作,但在 10.5 上它对我啁啾叫“无法访问启动路径”。([NSApp isOnSnowLeopardOrBetter] 是一个检查 AppKit 版本号的类别)。

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]; 
4

3 回答 3

2

您应该改用 的 方法NSWorkspace,它确实考虑了Info.plist键。例如,使用-(BOOL)launchApplication:(NSString*).

于 2010-02-03T05:58:35.317 回答
0

这是因为您在完整路径中使用空格,在数组中使用参数[NSArray arrayWithObjects:@"/usr/bin/arch",@"-i386",@"-ppc",path,nil]

于 2010-02-10T15:22:24.613 回答
0

尝试使用此代码重新启动您的应用程序:

//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];
   }
}
于 2012-08-07T10:13:48.070 回答