SMJobBless错误

时间:2015-06-24 07:58:23

标签: ios macos cocoa smjobbless

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

错误Domain = CFErrorDomainLaunchd Code = 8"操作无法完成。 (CFErrorDomainLaunchd错误8。)

我验证了代码符号,应用程序和辅助工具的plist,在launchServices中复制了该工具并且还链接了plists。

有人可以帮助我吗?

谢谢,

3 个答案:

答案 0 :(得分:4)

验证以下事项:

1.Code

- (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;
}

2.在info.plist(主应用程序)

中的安装字段后拥有的工具
helper bundle : identifier <Helper Bundle Identifier> and certificate leaf[subject.CN] = "Developer ID Application: xxxxx (YYXSFDHZ6W)"

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

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

4.检查xxxxHelperTool-Launchd.plist.it中提交的MachServices应该是

helper tool bundle : YES

答案 1 :(得分:1)

在(否则被替换的示例代码)SMJobBless示例代码:https://developer.apple.com/library/archive/samplecode/SMJobBless/Introduction/Intro.html

中找到工具SMJobBlessUtil.py。

注意:SMJobBless IS 是祝福工作的正确方法。旧的方式AuthorizationExecuteWithPrivileges已被弃用,并将在不久的将来积极地避开。不推荐使用“ SMJobBless” 示例代码,因为以下示例代码在各个方面都具有优越性。

确定,获取工具,现在获取当前示例代码: https://developer.apple.com/library/archive/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html

使用SMJobBlessUtil.py脚本来验证和/或设置主程序和帮助器中的Info.plist内容。

答案 2 :(得分:1)

1,您可以使用SMJobBlessUtil.py检查您的应用;也许会出现一些错误说明,例如dump malformed;

2,然后,您可以比较示例代码的项目设置,找到辅助目标other linker flags,看看是否应进行设置。