0
@implementation button
- (IBAction)doSomething:(id)pId;
{

    NSFileManager *filemgr;
    NSString *currentpath;
    NSString *appPath;

    filemgr = [[NSFileManager alloc] init];
    currentpath = [filemgr currentDirectoryPath];

    appPath=[currentpath stringByAppendingString:@"/resources/systemRun.app"];
    [[NSWorkspace sharedWorkspace] openFile:appPath withApplication:nil];

    exit(0);
}
@end

当我从 Xcode 构建和运行时,或者当我在 Xcode 中右键单击“产品”时,此代码可以完美运行。但是,当我从 finder 运行应用程序时,它永远不会启动......即使在非常构建文件夹中...... wtf ?

4

1 回答 1

0

不要currentDirectoryPath用于查找您的资源目录。

NSString *appPath = [[NSBundle currentBundle] pathForResource:@"systemRun" ofType:@"app"];
于 2011-09-01T23:33:24.363 回答