Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 启动守护进程可以运行什么类型的文件?_Objective C_Macos_Cocoa_Launchd - Fatal编程技术网

Objective c 启动守护进程可以运行什么类型的文件?

Objective c 启动守护进程可以运行什么类型的文件?,objective-c,macos,cocoa,launchd,Objective C,Macos,Cocoa,Launchd,我正试图使用SMJobSubmit从普通桌面应用程序中启动一个Unix可执行文件,该文件是我在Xcode中创建的。(GUI部分应该调用命令行辅助工具。) 下面是我用来提交作业的代码 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [authView setString:kSMRightModifySystemDaemons]; [authView setAutoupdate:YES];

我正试图使用
SMJobSubmit
从普通桌面应用程序中启动一个Unix可执行文件,该文件是我在Xcode中创建的。(GUI部分应该调用命令行辅助工具。)

下面是我用来提交作业的代码

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [authView setString:kSMRightModifySystemDaemons];
    [authView setAutoupdate:YES];
    [authView setDelegate:self];
}

- (IBAction)pressedButton:(id)sender
{
    /*
      authView is an instance of SFAuthorizationView. At this point, the user
      already clicked the padlock and entered his password.
    */
    authRef = [[authView authorization] authorizationRef];

    //toolPath points to the file in the app's Resource folder.
    NSArray* call = [NSArray arrayWithObject:toolPath];

    NSDictionary* jobSpec = [NSDictionary dictionaryWithObjectsAndKeys:
                             call, @"ProgramArguments",
                             jobLabel, @"Label",
                             [NSNumber numberWithBool:YES], @"RunAtLoad",
                             nil];

    CFErrorRef submitError = nil;
    BOOL submitResult = SMJobSubmit(kSMDomainSystemLaunchd,
                                    (__bridge CFDictionaryRef)(jobSpec),
                                    authRef,
                                    &submitError);

    if(!submitResult)
    {
        NSLog(@"Job submit failed. %@", submitError);
        return;
    }
}   
submitResult
结果总是
true
,但我的程序似乎从未执行过。我已经通过终端手动执行了我的程序,它工作得很好;助手工具应该将文件写入文件系统上的某个位置,并且不接受任何参数。然而,当我将它发送到启动守护进程时,什么也没有发生。它被标记为可执行文件。我还验证了路径。没错


所以,我想知道启动守护进程是否只能运行某些类型的文件?除非我在代码中弄错了什么。

您创建的授权引用应该有权使用launchd运行可执行文件

通过使用

[authview设置授权权限:kSMRightModifySystemDaemons]

大会发言

authRef=[[authView authorization]authorizationRef];


事情应该会成功的。您可能需要包含
来定义
kSMRightModifySystemDaemons

我已经发布了更多的代码。我有
[authView设置字符串:kSMRightModifySystemDaemons]在my
ApplicationIDFinishLaunching
方法中。API说,“在视图正确显示之前,必须调用此方法或
setAuthorizationRights:
方法。”