gpt4 book ai didi

cocoa - IOBluetoothDevice openConnection 失败 - 识别错误代码

转载 作者:行者123 更新时间:2023-12-03 17:53:46 25 4
gpt4 key购买 nike

我正在编写一个使用蓝牙的 Cocoa 应用程序。我正在尝试连接到蓝牙设备,但失败。

IOBluetoothDevice *btDevice;

// I do search and find the device
btDevice = ;//device found
//btDevice is not nil

IOReturn status = [btDevice openConnection];
if (status != kIOReturnSuccess) {
NSLog( @"Error - failed to connect. %d", status );
}

我在搜索时获取了设备,但 openConnection 方法失败。 NSLog 打印

Error = failed to connect. 4

现在这个错误代码表示什么?我查看了 IOKit.framework/IOReturn.h 文件,它显示了许多错误代码

#define kIOReturnError           iokit_common_err(0x2bc) // general error   
#define kIOReturnNoMemory iokit_common_err(0x2bd) // can't allocate memory
#define kIOReturnNoResources iokit_common_err(0x2be) // resource shortage
#define kIOReturnIPCError iokit_common_err(0x2bf) // error during IPC
#define kIOReturnNoDevice iokit_common_err(0x2c0) // no such device
.......
//And many more

我写了一个函数来识别错误代码4是什么

- (void)logError:(OSStatus)status{
if (status == kIOReturnError) {
NSLog(@"kIOReturnError");
}else if(status == kIOReturnNoMemory){
NSLog(@"kIOReturnNoMemory");
}else if(status == kIOReturnNoResources){
NSLog(@"kIOReturnNoResources");
}else if(status == kIOReturnIPCError){
NSLog(@"kIOReturnIPCError");
}else if(status == kIOReturnNoDevice){
......
......
}else{
NSLog(@"No price for you");
}
}

然后打印出来

No price for you

错误代码 4 意味着什么?还有没有更简单的方法可以从 OSStatus 错误代码中识别错误原因?

最佳答案

[IOBluetoothDevice openConnection] 在您的 logError: 方法测试时返回 IOReturn 代码(这是 I/O Kit 特定的错误号)用于 OSStatus 代码。
OSStatus 与 IOReturn 不同。

Apple 有一个技术问答,解释了查找 I/O Kit 错误的宏。 http://developer.apple.com/library/mac/#qa/qa1075/_index.html

在您的情况下,这似乎是一个 Mach 错误(这可能是错误的 0x4 hi 位,在您的日志行中显示为十进制 4)。

关于cocoa - IOBluetoothDevice openConnection 失败 - 识别错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17230303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com