IOS 6 bluetoothmanager integrating private api

I am trying to establish a connection with a third-party Bluetooth device with an iPhone 4 with iOS6 and use the Bluetooth headset as an example. After checking many guides and guides on this issue, I came to the following conclusions:

a. The most suitable way for me to communicate is to use the "private IOS bluetoothManager infrastructure". (I do not need to upload it to the application store)

b - Steps:

  • Find device
  • Get information (address)
  • couple
  • communicate

c - There seems to be no way to make it work :(

I based my application on this: Bluetooth and iOS - use Bluetooth in your iPhone applications and wrote my application based on it.

When I run it, the application detects a 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 connect to the device, I get the following message in the 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:

 - (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.

Glory.

+6
source share
2 answers

Try this solution. It worked for me.

 BluetoothManager *btManager = [BluetoothManager sharedInstance]; [btManager setDevicePairingEnabled:true]; [btManager setConnectable:true]; [btManager setPincode:@"0000" forDevice:device]; [btManager connectDevice:device]; 
+2
source

Hope this helps you, you can try with service tag 0x00002000

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

Source: https://habr.com/ru/post/978894/


All Articles