我正在编写一个使用蓝牙的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打印
错误=无法连接。 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");
}
}
打印
没有价格
错误代码4意味着什么?还有更简单的方法从OSStatus错误代码中识别错误原因吗?
答案 0 :(得分:1)
[IOBluetoothDevice openConnection]
方法测试OSStatus代码时, IOReturn
会返回logError:
代码(这是I / O Kit特定的错误编号)。
OSStatus与IOReturn不同。
Apple有一个技术问答,解释了查找I / O Kit错误的宏。 http://developer.apple.com/library/mac/#qa/qa1075/_index.html
在你的情况下,它似乎是一个Mach错误(可能是错误的0x4 hi位,在你的日志行中显示为十进制4)。
答案 1 :(得分:0)
我认为4
回复实际上是kBluetoothHCIErrorPageTimeout
。我发现的唯一代码是:https://www.ida.liu.se/~TDDD63/projects/2013/mindstorms/Installation/Mac/lightblue-0.4-master/src/mac/_bluetoothsockets.py