我们在使用SMJobBless更新帮助工具时遇到了问题,这个工具一直困扰着我们好几天.
我们正在开发一个应用程序,在某些时候我们需要执行管理任务(加载/卸载kext).我们还使用钥匙串存储我们的应用程序的帐户信息.
对于管理任务,我们使用一个使用SMJobBless安装的辅助工具,我们使用DO over Mach端口(使用NSConnection)与之交流.
在帮助工具中:
// use our bundle id as our service name
NSString* name = [[NSBundle mainBundle] bundleIdentifier];
launch_data_t checkinRequest = launch_data_new_string(LAUNCH_KEY_CHECKIN);
launch_data_t checkinResponse = launch_msg(checkinRequest);
launch_data_t machServicesDict = launch_data_dict_lookup(checkinResponse, LAUNCH_JOBKEY_MACHSERVICES);
launch_data_t machPort = launch_data_dict_lookup(machServicesDict, [name UTF8String]);
mach_port_t mp = launch_data_get_machport(machPort);
launch_data_free(checkinResponse);
launch_data_free(checkinRequest);
NSMachPort *receivePort = [[NSMachPort alloc] initWithMachPort:mp];
NSConnection *server = [NSConnection connectionWithReceivePort:receivePort sendPort:nil];
Run Code Online (Sandbox Code Playgroud)
在应用程序中:
NSConnection *conn = [NSConnection connectionWithRegisteredName:HELPER_BUNDLE_IDENTIFIER host:nil];
id proxyServerObject = [conn rootProxy];
if(conn && proxyServerObject) {
return [proxyServerObject someMethod];
} …Run Code Online (Sandbox Code Playgroud)