0

I want to upload a screen saver to the app store, after contacting them I was told to encapsulate the .saver inside the .app

I want to build a simple .app that launches the .saver which is in its bundle. However I failing to do so :(

I tried several solutions with NSTask and NSWorkspace but none works :(

Here are some attempts

    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"

What is the approach to launch it ?

4

1 回答 1

0

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

    [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以便让它从用户空间运行 Pathes。

于 2015-07-07T19:31:52.613 回答