SMJobBless 给出错误 CFErrorDomainLaunchd Code=8

Pri*_*Raj 2 macos cocoa smjobbless

我正在尝试通过 SMJobBless 安装辅助工具,但收到以下错误,

\n\n

错误域=CFErrorDomainLaunchd代码=8“操作无法完成\xe2\x80\x99。(CFErrorDomainLaunchd错误8。)

\n\n

我验证了代码签名、应用程序的 plist 和辅助工具,将工具复制到 launchServices 中并链接了 plist。

\n\n

谁能帮帮我吗?

\n\n

谢谢你,

\n

Fai*_*wal 6

验证以下事项:

1.代码

- (BOOL)blessHelperWithLabel:(NSString *)label
                       error:(NSError **)error {   

    BOOL result = NO;

    AuthorizationItem authItem      = { kSMRightBlessPrivilegedHelper, 0, NULL, 0 };
    AuthorizationRights authRights  = { 1, &authItem };
    AuthorizationFlags flags        =   kAuthorizationFlagDefaults              |
    kAuthorizationFlagInteractionAllowed    |
    kAuthorizationFlagPreAuthorize          |
    kAuthorizationFlagExtendRights;

    AuthorizationRef authRef = NULL;

    /* Obtain the right to install privileged helper tools (kSMRightBlessPrivilegedHelper). */
    OSStatus status = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, flags, &authRef);
    if (status != errAuthorizationSuccess) {
        NSLog(@"%@", [NSString stringWithFormat:@"Failed to create AuthorizationRef. Error code: %d", (int)status]);

    } else {
        /* This does all the work of verifying the helper tool against the application
         * and vice-versa. Once verification has passed, the embedded launchd.plist
         * is extracted and placed in /Library/LaunchDaemons and then loaded. The
         * executable is placed in /Library/PrivilegedHelperTools.
         */
        result = SMJobBless(kSMDomainSystemLaunchd, (CFStringRef)label, authRef, (CFErrorRef *)error);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

2.info.plist(主应用程序)中安装后拥有的工具字段

helper bundle : identifier <Helper Bundle Identifier> and certificate leaf[subject.CN] = "Developer ID Application: xxxxx (YYXSFDHZ6W)"
Run Code Online (Sandbox Code Playgroud)

3.客户端允许在helper info.plist中添加和删除工具字段。

item 0 : identifier <Main App Bundle Identifier> and certificate leaf[subject.CN] = "Developer ID Application: xxxxxx (YYXSFDHZ6W)"
Run Code Online (Sandbox Code Playgroud)

4.检查xxxxHelperTool-Launchd.plist.it中归档的MachServices应该是

helper tool bundle : YES
Run Code Online (Sandbox Code Playgroud)