我在写一个使用蓝牙的Cocoa应用程序。我正尝试连接到蓝牙设备,但失败。IOBluetoothDevice openConnection失败 - 识别错误代码
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");
}
}
而且它打印
没有价格你
什么是e错误代码4暗示?还有什么更容易的方法来识别来自OSStatus错误代码的错误原因吗?
你是对的OSStatus部分,即使我正在检查函数中的不同IOReturn错误代码。我弄错了方法原型。我正在检查你的链接。 – Krishnabhadra