Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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 守护进程是';t装载SMC_Objective C_Macos_Daemon_Launchd - Fatal编程技术网

Objective c 守护进程是';t装载SMC

Objective c 守护进程是';t装载SMC,objective-c,macos,daemon,launchd,Objective C,Macos,Daemon,Launchd,我想写一个程序,用SMJobSubmit()API加载一个守护进程 这是我的密码: int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString* myLabel = @"com.apple.mydaemon"; AuthorizationItem authItem = { kSMRightBlessPr

我想写一个程序,用SMJobSubmit()API加载一个守护进程 这是我的密码:

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSString* myLabel = @"com.apple.mydaemon";

    AuthorizationItem authItem = { kSMRightBlessPrivilegedHelper, 0, NULL, 0 };
    AuthorizationRights authRights = { 1, &authItem };
    AuthorizationFlags flags = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
    NSString *executablePath=@"/usr/libexec/mydaemon";
    AuthorizationRef auth;
    CFErrorRef error=0;
    if( AuthorizationCreate( &authRights, kAuthorizationEmptyEnvironment, flags, &auth ) == errAuthorizationSuccess ) {
        (void) SMJobRemove( kSMDomainSystemLaunchd, (CFStringRef)myLabel, auth, false, NULL );
        //NSLog( @"Authenticated install submit failed with error %@", error );

        NSMutableDictionary *plist = [NSMutableDictionary dictionary];
        NSMutableDictionary * programArgumnets=[NSMutableDictionary new];
        [programArgumnets setObject:executablePath forKey:@"item0"];
        [plist setObject:myLabel forKey:@"Label"];
        [plist setObject:programArgumnets forKey:@"ProgramArguments"];
        [plist setObject:[NSNumber numberWithBool:YES] forKey:@"RunAtLoad"];
        [plist setObject:[NSNumber numberWithBool:YES] forKey:@"KeepAlive"];

        if ( SMJobSubmit( kSMDomainUserLaunchd, (CFDictionaryRef)plist, auth, &error) ) {
            // Script is running
        } else {
            NSLog( @"Authenticated install submit failed with error %@", error );
        }
        if ( error ) {
            CFRelease( error );
        }

            (void) SMJobRemove( kSMDomainSystemLaunchd, (CFStringRef)myLabel, auth, false, NULL );
        AuthorizationFree( auth, 0 );
    }

    [pool drain];
    return 0;
}
但它给出了这样一个错误:

SMJobSubmit[822:707]已验证的安装提交失败,错误为Domain=kSMErrorDomainFramework Code=2051“操作无法完成。(kSMErrorDomainFramework错误2051-指定加载到launchd的作业无效。)“UserInfo=0x100115750{NSDescription=指定加载到launchd的作业无效。”

有什么问题?
提前谢谢

程序参数不应为空。ProgramArguments数组的第一个元素应与程序键相同。有关更多详细信息,请参阅launchd文档和execvp手册页