IOCreatePlugInInterfaceForService返回神秘错误 [英] IOCreatePlugInInterfaceForService returns mysterious error

查看:46
本文介绍了IOCreatePlugInInterfaceForService返回神秘错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新的Swift 4.0 Mac应用程序(而非iOS)中使用一些旧的IOKit功能.我创建了一个桥接标头,以使用现有的Objective C第三方框架DDHidLib,并且当前正在使用Xcode 9.

I am trying to use some old IOKit functionality in a new Swift 4.0 Mac app (not iOS). I have created a bridging header to use an existing Objective C third party framework, DDHidLib, and I am current working in Xcode 9.

试图为USB游戏手柄创建插件接口的代码落在IOCreatePlugInInterfaceForService上,返回非零错误.

The code that attempts to create a plug in interface for a usb gamepad falls over on IOCreatePlugInInterfaceForService, returning a non-zero error.

真正奇怪的是,我在旧版本的Xcode中创建了一个较旧的应用程序,该应用程序使用相同的框架,并在新的Xcode 9中打开后可以正常运行.该先前的项目仍然是Swift,对于同一Obj使用桥接头-C框架.我已经检查了构建设置,并尝试使所有内容匹配,但是得到的结果是相同的.旧应用程序可以运行,但任何新应用程序都不能.

The truly bizarre thing is I have an older app created in a previous version of Xcode that uses the same framework and works correctly after opening in the new Xcode 9. This previous project is still Swift using a bridging header for the same Obj-C framework. I have checked the build settings and tried to make everything match, but I get the same result; the old app works but any new apps do not.

是否有办法:找出构建设置/编译器中的确切差异,以查看可能存在的难以捉摸的差异,或者进入IOCreatePlugInInterfaceForService IOKit方法,以查看可能导致错误返回的原因之一项目而不是其他项目?

Is there a way to either: find out the exact differences in build settings/compilers to see what the elusive difference may be, OR to step into the IOCreatePlugInInterfaceForService IOKit method to see what may be causing the error to be returned in one project but not another?

这是失败的方法:

- (BOOL) createDeviceInterfaceWithError: (NSError **) error_; {
io_name_t className;
IOCFPlugInInterface ** plugInInterface = NULL;
SInt32 score = 0;
NSError * error = nil;
BOOL result = NO;

mDeviceInterface = NULL;

NSXReturnError(IOObjectGetClass(mHidDevice, className));
if (error)
    goto done;

NSXReturnError(IOCreatePlugInInterfaceForService(mHidDevice, kIOHIDDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&plugInInterface,&score));
if (error)
    goto done;

//Call a method of the intermediate plug-in to create the device interface
NSXReturnError((*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &mDeviceInterface));
if (error)
    goto done;

result = YES;

done:
    if (plugInInterface != NULL)
    {
        (*plugInInterface)->Release(plugInInterface);
    }
    if (error_)
        *error_ = error;
    return result;
}

在可行的旧版本中,IOCreatePlugInInterfaceForService始终返回值0.在所有无效的版本中,返回值始终为-536870210.此函数中的mHidDevice是设备的io_object_t句柄.

In the old version that works, IOCreatePlugInInterfaceForService always returns a value of 0. In all the versions that don't work, the return value appears to always be -536870210. The mHidDevice in this function is the io_object_t handle for the device.

这是设备的IORegistryExplorer页面

Here is the IORegistryExplorer page for the device

推荐答案

经过数周的头部抓挠,终于设法解决了这一问题.新的Xcode 9使用应用程序沙箱从根本上阻止了新应用程序中默认情况下对USB,蓝牙,摄像头和麦克风等的访问.一旦我将其关闭,它就会恢复为预期的行为.

Finally managed to resolve this after weeks of head scratching. The new Xcode 9 uses app sandboxing to basically prevent access to USB, bluetooth, camera and microphone etc. by default in a new app. Once I switched this off it reverted to it's expected behaviour.

很高兴最后给出的答案很简单,但是令人失望的Xcode并没有提供更多描述性的错误消息或响应,以使用户知道他们本质上是在阻止自己访问所需的系统部分.

Glad it was such a simple answer in the end but disappointed Xcode does not provide more descriptive error messages or responses to let a user know they are essentially preventing themselves from accessing the parts of the system they need.

这篇关于IOCreatePlugInInterfaceForService返回神秘错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆