macOS开发—ServiceManagement.framework

零、ServiceManagement.framework简述

用来加载或者卸载守护进程服务。在应用内读取或调用launchd字典。简单来看这个框架很小

ServiceManagement.framework

它包含:ServiceManagement.h、SMErrors.h、SMLoginItem.h。

一、ServiceManagement.h

是ServiceManagement框架主要的头文件,这个头文件提供加载或者不加载守护进程应用,并从应用中读取和操作job字典

1、常量

1.1 kSMRightBlessPrivilegedHelper

/*!  

*@abstract

* The authorization rightskeyforblessingandinstalling a privileged helper 

* tool.  

* 用来安装高权限helper工具的授权key

/

#define kSMRightBlessPrivilegedHelper "com.apple.ServiceManagement.blesshelper"

1.2 kSMRightModifySystemDaemons

/*!

*@abstract

* The authorization rightskeyformodifyingsystemdaemons.  

* 用来调整系统守护进程的授权key*

/

#define kSMRightModifySystemDaemons "com.apple.ServiceManagement.daemons.modify"

2、常量

const CFStringRef kSMDomainSystemLaunchd:展示 Mach bootstrap 特权上下文的常量,使用这个上下文需要root权限。

const CFStringRef kSMDomainUserLaunchd:展示和调用者UID关联的 Mach bootstrap 上线文。在iOS中,这个词是 kSMDomainSystemLaunchd 的同义词。

3、方法

3.1 SMJobBless

Boolean SMJobBless(CFStringRef domain, CFStringRef executableLabel, AuthorizationRef auth, CFErrorRef *outError);

domain: 只支持 kSMDomainSystemLaunchd;

executableLabel(需要特权安装的):必须是应用程序 Info.plist 中 SMPrivilegedExecutables 中某个键对应的值;

auth:包含 kSMRightBlessPrivilegedHelper 权限的参数;

outError:提交执行工具时遇到错误的输出参数,提交成功的话,返回NULL。这个参数也可以为NULL。

二、SMErrors.h

包含ServiceManagement框架返回的错误码,使用时不需要特定引入这个框架,ServiceManagement.h已经引入。

三、SMLoginItem.h

包含的头文件:<sys/cdefs.h>

SMLoginItemSetEnabled 方法

只有一个方法:(Mac 10.6后可用,iPhone 不可用)

BooleanSMLoginItemSetEnabled(CFStringRef identifier,Boolean enabled);

允许helper 程序放在主程序包中的 Contents/Library/LoginItems 目录;

其中:参数 identifier 是这个helper 程序的 identifier。

参数 enabled 标记这个helper 程序的状态;这个值只有在当前用户登录后才有效。如果为true,helper程序会马上启动并一直运行;如果为false,就不会再运行。

结果返回为true,代表设置已经生效。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转自bireme,原地址:https://blog.ibireme.com/2015/05/18/runloop/...
    乜_啊_阅读 1,507评论 0 5
  • 总起 OS X是MacOS与NeXTSTEP的结合。OC是Smalltalk类面向对象编程与C的结合。iCloud...
    Flighting拾壹狼阅读 6,279评论 3 8
  • RunLoop 的概念 一般来讲,一个线程一次只能执行一个任务,执行完成后线程就会退出。如果我们需要一个机制,让线...
    Mirsiter_魏阅读 640评论 0 2
  • 前言 RunLoop是iOS和OSX开发中非常基础的一个概念,这篇文章将从CFRunLoop的源码入手,介绍Run...
    暮年古稀ZC阅读 2,342评论 1 19
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,175评论 1 32