I am writing a Cocoa application which uses bluetooth. I am trying to connect to a bluetooth device but it fails.
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 );
}
And I get the device when searches, but openConnection
method fails. And NSLog prints
Error = failed to connect. 4
Now what this error code indicates?
I looked at IOKit.framework/IOReturn.h
file and it shows many error codes
#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
And I wrote a function to identify what is error code 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");
}
}
And it prints
No price for you
What does error code 4 imply? Also is there any easier way to identify error reason from OSStatus error codes?