我尝试使用iOS6的iPhone 4s与第三方蓝牙设备进行通信,并使用蓝牙耳机作为示例。 在检查了很多关于这个主题的指南和教程之后,我得出了以下结论:
a-让我进行沟通工作的最合适方式是使用" IOS bluetoothManager私有框架"。 (我不需要将其上传到应用商店)
b - 步骤如下:
c - 显然没有办法让它发挥作用:(
我的应用基于:Bluetooth and iOS – Use Bluetooth in your iPhone apps,并根据它编写了我的应用。
当我运行它时,应用会找到耳机设备
xcode输出控制台:
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
当我尝试与设备配对时,我在xcode控制台中收到以下消息:
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
连接代码:
- (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]);
}
有什么问题? 什么是错误158?
任何帮助都将不胜感激。
光荣。
答案 0 :(得分:2)
试试这个解决方案。它对我有用。
BluetoothManager *btManager = [BluetoothManager sharedInstance];
[btManager setDevicePairingEnabled:true];
[btManager setConnectable:true];
[btManager setPincode:@"0000" forDevice:device];
[btManager connectDevice:device];
答案 1 :(得分:0)
我希望这会对你有所帮助,你可以试试服务标签0x00002000
BluetoothManager *btManager = [[self bluetoothScanner] bluetoothManager];
[btManager setDevicePairingEnabled:YES];
[btManager connectDevice:bluetoothDevice withServices:0x00002000];