无法从macOS应用连接DriverKit系统扩展(DEXT)求助
macOS应用与DriverKit系统扩展(DEXT)连接问题排查求助
我正在开发一款macOS应用,需要与基于DriverKit创建的系统扩展(DEXT)通信。尽管扩展已安装并激活,但应用始终无法与DEXT建立连接,具体细节如下:
- DEXT的Bundle标识符为
com.Henhen1227.KeySoundboard.SoundboardDriver; systemextensionsctl list显示DEXT已安装并激活:
--- com.apple.system_extension.driver_extension enabled active teamID bundleID (version) name [state] * * ---------- com.Henhen1227.KeySoundboard.SoundboardDriver (1.0/1) com.Henhen1227.KeySoundboard.SoundboardDriver [activated enabled]
- 应用中尝试通过
IOServiceGetMatchingService连接DEXT,但未返回匹配服务,无法建立用户客户端连接; ioreg -l -b命令未输出任何与该DEXT相关的信息。
开发环境:macOS 13.4.1、Xcode 14.3.1 (14E300c),DEXT代码参考Apple官方音频驱动示例,即使运行未修改的示例代码(已正确签名配置),仍出现相同问题。
相关代码片段
激活扩展的Swift代码(在viewDidLoad中调用)
/// - Tag: ActivateExtension func activateExtension(_ dextIdentifier: String) { let request = OSSystemExtensionRequest .activationRequest(forExtensionWithIdentifier: dextIdentifier, queue: .main) print(dextIdentifier) print(request.description) request.delegate = self OSSystemExtensionManager.shared.submitRequest(request) }
连接DEXT的Objective-C代码(激活5秒后主线程调用,持续返回“Driver Extension is not running.”)
// Open a user client instance, which initiates communication with the driver. - (NSString*) open { if (_ioObject == IO_OBJECT_NULL && _ioConnection == IO_OBJECT_NULL) { // Get the IOKit main port. mach_port_t theMainPort = MACH_PORT_NULL; kern_return_t theKernelError = IOMainPort(bootstrap_port, &theMainPort); NSLog(@"theMainPort: %u, theKernelError: %u", theMainPort, theKernelError); if (theKernelError != kIOReturnSuccess) { return @"Failed to get IOMainPort."; } // Create a matching dictionary for the driver class. Note that classes // published by a dext need to be matched by class name rather than // other methods. So be sure to use IOServiceNameMatching rather than // IOServiceMatching to construct the dictionary. CFDictionaryRef theMatchingDictionary = IOServiceNameMatching(kSoundboardDriverClassName); // kSoundboardDriverClassName = "SoundboardDriver" NSLog(@"theMatchingDictionary: %@", theMatchingDictionary); io_service_t matchedService = IOServiceGetMatchingService(theMainPort, theMatchingDictionary); NSLog(@"matchedService: %u", matchedService); theKernelError = IOObjectRelease(matchedService); NSLog(@"IOObjectRelease theKernelError: %u", theKernelError); if (theKernelError != KERN_SUCCESS) { return @"IOServiceGetMatchingService failed with error: %u"; } if (matchedService) { _ioObject = matchedService; theKernelError = IOServiceOpen(_ioObject, mach_task_self(), 0, &_ioConnection); NSLog(@"_ioObject: %u, _ioConnection: %u, IOServiceOpen theKernelError: %u", _ioObject, _ioConnection, theKernelError); if (theKernelError == kIOReturnSuccess) { OSStatus error = [self checkDeviceCustomProperties]; if (error) { return @"Connection to user client succeeded, but custom properties could not be validated"; } return @"Connection to user client succeeded"; } else { _ioObject = IO_OBJECT_NULL; _ioConnection = IO_OBJECT_NULL; return [NSString stringWithFormat:@"Failed to open user client connection, error:%u.", theKernelError]; } } return @"Driver Extension is not running"; } return @"User client is already connected"; }
补充日志信息
Console中捕获的扩展启动错误
activateDecision found two entries for teamID("5BHAWQJGY5") com.Henhen1227.KeySoundboard.SoundboardDriver in state: 7B8B8559-3F37-4236-B39B-DE0CB791DD37 (1.1): terminating_for_upgrade_via_delegate 11C738A7-A013-4464-95C6-0AB5829B66CC (1.1): activated_enabled
重复运行systemextensionsctl list的输出
5BHAWQJGY5 com.Henhen1227.KeySoundboard.SoundboardDriver (1.1/2) SoundboardDriver [terminating for upgrade via delegate] * * 5BHAWQJGY5 com.Henhen1227.KeySoundboard.SoundboardDriver (1.1/2) SoundboardDriver [activated enabled]
恳请提供排查思路与解决方案,帮助解决应用与DEXT的连接问题。
内容的提问来源于stack exchange,提问作者Henhen1227
相关产品推荐
相关产品推荐

