我在 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];