运行 来自 objective c Xcode 的 .saver 文件

Run .saver file from objective c Xcode

我想上传一个屏幕保护程序到应用商店,在联系他们后我被告知将.saver封装在.app中

我想构建一个简单的 .app 来启动其捆绑包中的 .saver。 但是我没有这样做:(

我用 NSTaskNSWorkspace 尝试了几种解决方案,但 none 有效:(

这里有一些尝试

    if(![[NSWorkspace sharedWorkspace] launchApplication:@"/Users/romanl/Desktop/XsaverApp/XsaverApp/SCTEST.saver/Contents/MacOS/SCTEST"])
    NSLog(@"Path Finder failed to launch");



    NSTask * task = [[NSTask alloc] init];
   [task setLaunchPath:@"/Users/romanl/Desktop/XsaverApp/XsaverApp/SCTEST.saver/Contents/MacOS/SCTEST"];
   [task launch];//Outputs : "Couldn't posix_spawn: error 8"

启动方法是什么?

好吧,我现在解决了... 如果有人对未来感兴趣,我会在此处发布答案

    [self.window close];
    NSTask * installTask = [[NSTask alloc]init];
    NSBundle * bundle = [NSBundle mainBundle];

    NSString * saverPath = [bundle pathForResource:@"CatsScreenSaver" ofType:@"saver"];

    NSMutableString * launchString = [[NSMutableString alloc]initWithString:@"open "];
    [launchString appendString:saverPath];

    [installTask setLaunchPath:@"/bin/bash"];

    NSArray *args = [NSArray arrayWithObjects:@"-l",
                 @"-c",
                 launchString,
                 nil];
    [installTask setArguments: args];
    [installTask launch ];

    [installTask waitUntilExit];
    [NSApp terminate:self];

棘手的部分在这里

        NSArray *args = [NSArray arrayWithObjects:@"-l",
                 @"-c",
                 launchString,
                 nil];
        [installTask setArguments: args];

应该将这些参数放在 NSTask 中,以便让它 运行 来自用户的路径 space。