Click here to Skip to main content
15,881,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to communicate with a 3rd party bluetooth device from an iPhone 4s with iOS6, and using a bluetooth headset as an example.
After checking many guides and tutorials on the subject, I came to the following conclusions:

a -The most suitable way for me to make communication work is to use "IOS bluetoothManager private framework". (I don't need to upload it to app store)

b - The steps are:
1. Find the device
2. Get his info (address)
3. pair
4. communicate

c - Apparently there is no way to make it work :(

I based my app on this: [Bluetooth and iOS – Use Bluetooth in your iPhone apps][1], and wrote my app based on it.

When I run it, the app finds the headset device

xcode output console:
2014-11-30 14:31:57.041 BluetoothNew[146:907] BTM: attaching to BTServer
2014-11-30 14:31:57.050 BluetoothNew[146:907] BTM: enabling device scanning
2014-11-30 14:32:00.451 BluetoothNew[146:907] BTM: found device "UA06XB-B" 20:14:05:12:7A:3B
2014-11-30 14:32:00.454 BluetoothNew[146:907] Name: UA06XB-B
Address: 20:14:05:12:7A:3B
MajorClass: 1024
MinorClass:4
Type:16
BatteryLevelSupport: 0


When I try to pair to the device I get the following message in xcode console:

    2014-11-30 14:32:04.686 BluetoothNew[146:907] BTM: setting pincode '0000' for device "UA06XB-B" 20:14:05:12:7A:3B
    2014-11-30 14:32:04.688 BluetoothNew[146:907] BTM: connecting to device "UA06XB-B" 20:14:05:12:7A:3B
    2014-11-30 14:32:07.303 BluetoothNew[146:907] BTM: attempting to connect to service 0x00000001 on device "UA06XB-B" 20:14:05:12:7A:3B
    2014-11-30 14:32:07.938 BluetoothNew[146:907] BTM: connection to service 0x00000001 on device "UA06XB-B" 20:14:05:12:7A:3B failed with error 158 



connection code:

Objective-C
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
    NSString *labelText = cell.textLabel.text;

    BluetoothDevice *device =  [self.currentAvailableDevices objectForKey:labelText];
    BluetoothManager *btManager =   [[self bluetoothScanner]getBluetoothManager];
    [btManager setPincode:@"0000" forDevice:(device)];
    [btManager connectDevice:device];


    // I tried this way too with the same result

    //[device setPIN:@"0000"];
    //[device  connect];
    //NSLog(@"service supported: %d", [device isServiceSupported:0x00000001]);
}


What is the problem?
What is error 158?

Any help would be appreciated.

Slava.
Posted

Looks like the exotic "UA06XB-B" device isnt properly supporting the bt-service 0x00000001.

What are the return codes of the other API?

On Github is also some iOS private framework "BluetoothManager" but for iOS 7.

It is the old problem: you should not use private API because it can change in different version. At most iOS 6 is really outdated. You better dig one more in the Apple documentation. ;-)
 
Share this answer
 
Comments
skcoding 1-Dec-14 15:39pm    
UA06XB-B is a standart headset device.
I manage to pair it with no problem in the standart way (settings -> bluetooth).
The problem is when I try to do it programmatically.

Do you know what does 0x00000001 service means?
What is error 158?

Thanks..
I Hope this would help you,you can try with service tag 0x00002000

BluetoothManager *btManager = [[self bluetoothScanner] bluetoothManager];
[btManager setDevicePairingEnabled:YES];
[btManager connectDevice:bluetoothDevice withServices:0x00002000];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900