首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 6蓝牙管理器配对私有api

iOS 6蓝牙管理器配对私有api
EN

Stack Overflow用户
提问于 2014-11-30 13:00:49
回答 2查看 2K关注 0票数 6

我正在尝试与第三方蓝牙设备从iPhone 4与iOS6通信,并以蓝牙耳机为例。在查阅了许多关于这一主题的指南和教程之后,我得出了以下结论:

对于我来说,-The最适合的通信方式是使用"IOS bluetoothManager私有框架“。(我不需要上传到应用商店)

B-步骤如下:

  1. 找到那个装置
  2. 获取他的信息(地址)
  3. 配对
  4. 沟通

显然,没有办法让它发挥作用:

我把我的应用程序建立在这个基础上:Bluetooth and iOS – Use Bluetooth in your iPhone apps,并以此为基础编写我的应用程序。

当我运行它时,应用程序会找到耳机设备。

xcode输出控制台:

代码语言:javascript
复制
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控制台中得到以下消息:

代码语言:javascript
复制
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 

连接代码:

代码语言:javascript
复制
- (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?

任何帮助都将不胜感激。

斯拉夫人。

EN

回答 2

Stack Overflow用户

发布于 2015-05-18 06:33:37

试试这个解决方案。对我起作用了。

代码语言:javascript
复制
BluetoothManager *btManager = [BluetoothManager sharedInstance];
[btManager setDevicePairingEnabled:true];
[btManager setConnectable:true];
[btManager setPincode:@"0000" forDevice:device];
[btManager connectDevice:device];
票数 2
EN

Stack Overflow用户

发布于 2015-02-02 15:43:40

我希望这对你有帮助,你可以尝试使用服务标签0x00002000。

代码语言:javascript
复制
BluetoothManager *btManager =  [[self bluetoothScanner] bluetoothManager];
[btManager setDevicePairingEnabled:YES];
[btManager connectDevice:bluetoothDevice withServices:0x00002000];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27213511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档