标签: iobluetooth

列出Swift中蓝牙设备范围内的设备

我在Xcode 6游乐场中有以下代码:

import Cocoa
import IOBluetooth

class BlueDelegate : IOBluetoothDeviceInquiryDelegate {
    func deviceInquiryComplete(sender: IOBluetoothDeviceInquiry, error: IOReturn, aborted: Bool) {
        aborted
        var devices = sender.foundDevices()
        for device : AnyObject in devices {
            if let thingy = device as? IOBluetoothDevice {
                thingy.getAddress()
            }
        }
    }
}

var inquiry = IOBluetoothDeviceInquiry(delegate: BlueDelegate())
inquiry.start()
Run Code Online (Sandbox Code Playgroud)

我刚开始使用OSX下的蓝牙,而我目前想要的只是范围内的设备列表.

它似乎根本没有调用我的委托方法.

我是OSX开发和Swift的新手,所以请保持温和.:)

macos bluetooth iobluetooth swift

8
推荐指数
1
解决办法
1万
查看次数

接受线程的IOException

我的应用程序的一部分通过蓝牙连接到设备,通常工作正常但偶尔它不会连接,我得到以下错误

03-11 10:29:20.328: E/BluetoothComService(8059): accept() failed
03-11 10:29:20.328: E/BluetoothComService(8059): java.io.IOException: Operation Canceled
03-11 10:29:20.328: E/BluetoothComService(8059):    at android.bluetooth.BluetoothSocket.acceptNative(Native Method)
03-11 10:29:20.328: E/BluetoothComService(8059):    at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:316)
03-11 10:29:20.328: E/BluetoothComService(8059):    at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:105)
03-11 10:29:20.328: E/BluetoothComService(8059):    at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:91)
03-11 10:29:20.328: E/BluetoothComService(8059):    at com.mypackage.name.bluetooth.BluetoothService$AcceptThread.run(BluetoothService.java:298)
Run Code Online (Sandbox Code Playgroud)

这是我得到例外的那一行

socket = mmServerSocket.accept();    
Run Code Online (Sandbox Code Playgroud)

这是完整的AcceptThread

private class AcceptThread extends Thread {
    // The local server socket
    private BluetoothServerSocket mmServerSocket;
    public boolean successInit = false;

    public AcceptThread() {
        closeAllConnections();

        /*
         * if(mmServerSocket != null) { try { mmServerSocket.close(); } catch
         * (IOException e) …
Run Code Online (Sandbox Code Playgroud)

android bluetooth ioexception iobluetooth

7
推荐指数
1
解决办法
5878
查看次数

如何建立L2Capp中断通道连接?

我试图打开L2Cap HID通道和中断通道,以便我可以将HID命令发送到蓝牙设备.

我已完成所有服务广告和设备配对并建立了基带连接.

Hid控制通道打开正常.当我尝试创建我的kBluetoothL2CAPPSMHIDInterrupt连接时

l2capChannelQueueSpaceAvailable

委托方法调用(不确定这意味着什么)后跟

l2capChannelOpenComplete

但连接立即关闭

l2capChannelClosed

我该如何正确打开这些连接?

我花了很长时间挖掘IOBlueTooth框架和bluetooth.org HID规范,但几乎没有任何有用的信息(我至少可以找到).

当我追踪我的L2Cap频道时,我看到了一些空值

mIncomingDataListener

mEventDataListener

.我不知道如何设置它们或者它们是否与我的问题有关....只是推测.

下面的代码片段是我到目前为止在建立与设备的连接后建立连接的尝试.

-(void)establishL2CappConnections:(IOBluetoothDevice*)device
{
    IOReturn r;
    IOBluetoothL2CAPChannel *ch1;
    r = [device openL2CAPChannelSync:&ch1
                             withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDControl
                            delegate:self];
    self.mL2CappChannel=ch1;
    NSLog(@"r == %i",r);

    IOBluetoothL2CAPChannel *ch2;
    r = [device openL2CAPChannelSync:&ch2
                             withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDInterrupt
                            delegate:self];
    self.mL2CappInterruptChannel=ch2;
    NSLog(@"r == %i",r);


}
Run Code Online (Sandbox Code Playgroud)

编辑:1

我已经附上了我的包日志.这很奇怪,是一个请求

kBluetoothL2CAPPSMSDP 0x0001

没有我请求它,然后一切开始断开连接.

BT数据包日志

macos bluetooth l2cap iobluetooth

7
推荐指数
1
解决办法
455
查看次数

如何通过IOBluetooth框架(macOS)获取BLE设备列表

我有一个问题,通过IOBluetooth框架列出所有设备.有没有办法不仅可以获得经典设备,还可以获得BLE设备?

我的代码是

let ioBluetoothManager = IOBluetoothDeviceInquiry(delegate: self)
var ioDevices = [IOBluetoothDevice]()
...
ioBluetoothManager?.start()
...

func deviceInquiryStarted(_ sender: IOBluetoothDeviceInquiry!) {
    print("started")
}
///
//IOBluetoothDeviceInquiryDelegate
///

func deviceInquiryDeviceFound(_ sender: IOBluetoothDeviceInquiry!, device: IOBluetoothDevice!) {
    print("found device")
    ioDevices.append(device)
    scrubber.reloadData()
    tableView.reloadData()
}

func deviceInquiryComplete(_ sender: IOBluetoothDeviceInquiry!, error: IOReturn, aborted: Bool) {
    print("completed")
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以用CoreBluetooth做到这一点,但我还需要过滤设备以符合某个标准.

这个答案我知道我可以做到这一点,但答案缺乏细节.现在我只是获得经典蓝牙设备列表.

有人可以帮忙吗?

UPD:

现在我找到了.searchType方法kIOBluetoothDeviceSearchClassickIOBluetoothDeviceSearchLE常量.在viewDidLoad中,我执行了以下操作:

ioBlutoothmanager.searchType = IOBluetoothDeviceSearchLE.rawValue 但它仍然只能找到经典的设备.

UPD:

这段时间它的工作正常我没想到.它过滤了我不需要的所有设备,我没有AirPods来检查.

macos bluetooth iobluetooth core-bluetooth

7
推荐指数
1
解决办法
485
查看次数

iOS输入麦克风输出蓝牙设备

我正在尝试从Mic获取输入并使用audioRouteOverride将其输出到我的蓝牙设备.但没有运气.iphone麦克风输出仍然是iphone内置扬声器.我期待kAudioSessionOutputRoute_BluetoothA2DP是这里的关键.但它没有按预期工作.

以下是我使用的代码:

- (id) init {
    self = [super init];

    OSStatus status;

    // Describe audio component
    AudioComponentDescription desc;
    desc.componentType = kAudioUnitType_Output;
    desc.componentSubType = kAudioUnitSubType_RemoteIO;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;

    // Get component
    AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);

    // Get audio units
    status = AudioComponentInstanceNew(inputComponent, &audioUnit);
    checkStatus(status);

    // Enable IO for recording
    UInt32 flag = 1;
    status = AudioUnitSetProperty(audioUnit, 
                                  kAudioOutputUnitProperty_EnableIO, 
                                  kAudioUnitScope_Input, 
                                  kInputBus,
                                  &flag, 
                                  sizeof(flag));
    checkStatus(status);

    // Enable IO for playback
    status = AudioUnitSetProperty(audioUnit, 
                                  kAudioOutputUnitProperty_EnableIO, 
                                  kAudioUnitScope_Output, 
                                  kOutputBus,
                                  &flag, …
Run Code Online (Sandbox Code Playgroud)

core-audio iobluetooth audiounit ios avaudiosession

6
推荐指数
1
解决办法
2805
查看次数

Mac到蓝牙设备文件传输,简单示例?

我花了两天的时间在谷歌上搜索并阅读了《蓝牙编程指南》,同时试图拼凑一个小型Mac应用程序,该应用程序将从放置文件夹中检索图像并将任何新文件通过蓝牙发送到预定的设备。似乎没有很多好的例子。

我现在可以生成蓝牙服务浏览器并选择设备及其OBEX服务,建立服务并创建连接,但是接下来什么也没有发生。谁能指出我的方向/向我展示一个简单的例子?

随附AppDelegate源代码。谢谢阅读!

#import“ AppDelegate.h”

@implementation AppDelegate

-(void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    IOBluetoothServiceBrowserController *浏览器= [IOBluetoothServiceBrowserController serviceBrowserController:0];
    [浏览器runModal];

    // IOBluetoothSDPServiceRecord
    IOBluetoothSDPServiceRecord * result = [[浏览器getResults] objectAtIndex:0];
    [自我描述:结果];

    如果([[result.device.name substringToIndex:8] isEqualToString:@“ Polaroid”]){
        打印机= result.device;
        serviceRecord =结果;
        [self testPrint];
    }
    其他{
        NSLog(@“%@不是有效的设备”,result.device.name);
    }
}

-(void)testPrint {
     currentFilePath = @“ / Users / oyvind / Desktop / _DSC8797.jpg”;
    [self sendFile:currentFilePath];
}

-(void)sendFile:(NSString *)filePath {
    IOBluetoothOBEXSession * obexSession = [[IOBluetoothOBEXSession alloc] initWithSDPServiceRecord:serviceRecord];

    if(obexSession!= nil)
    {
        NSLog(@“已建立OBEX会话”);

        OBEXFileTransferServices * fst = [OBEXFileTransferServices withOBEXSession:obexSession];
        OBEXDelegate * obxd = [[[OBEXDelegate …

macos cocoa bluetooth objective-c iobluetooth

5
推荐指数
1
解决办法
2289
查看次数

如何在OS X上获取设备蓝牙地址?

我已经看过IOBluetooth框架感觉十几次,但我不能为我的生活找到一种方法来检索当前设备的蓝牙设备地址.我编写了一个应用程序,利用IOBluetoothDeviceInquiry扫描范围内的设备,但这似乎没有提供进行扫描的设备的地址.

如何以编程方式完成此操作?(无需打开System Profiler)

macos cocoa bluetooth objective-c iobluetooth

4
推荐指数
1
解决办法
1652
查看次数

清除CoreBluetooth GATT缓存而不删除绑定

我有一个iOS应用程序充当外围设备和OS X应用程序充当核心,使用CoreBluetooth框架.OS X应用程序连接到iOS应用程序,它们通过读取加密特征并输入随机代码进行绑定.一切正常,直到iOS应用程序重新启动.从那时起,每次我连接到iOS设备并尝试读取它的任何特征时,它都会返回"Handle is invalid" - error.解决此问题的唯一方法是从OS X的蓝牙首选项中删除设备并重新启动绑定过程.

我怀疑这个问题是由OS X缓存我的设备的服务和特性引起的,当我重新启动一个iOS设备后,我发现这个问题没有出现.

我正在寻找的是一种清除OS X缓存我的服务和特性的方法.我熟悉删除com.apple.Bluetooth.plist并重新启动蓝色进程/打开/关闭蓝牙的方法.(是否发蓝缓存ATT值,以及如何清除缓存?我如何清除在MacOS的CoreBluetooth缓存?)

但是,删除com.apple.Bluetooth.plist需要我再次与iOS设备绑定并输入代码.有没有办法清除缓存,但只能使用与我的应用程序相关的服务/特性?

macos caching bluetooth iobluetooth core-bluetooth

3
推荐指数
1
解决办法
2347
查看次数

核心蓝牙和IOBluetooth有什么区别

这个问题已经在 2013 年在 Stack Overflow上提出过,但需要更新。自 macOS 10.13 以来,针对 macOS 的核心蓝牙功能进行了更改,使其更加符合 iOS。

\n

该问题的答案是

\n
\n

CoreBluetooth 是用于蓝牙 LE 通信的 iOS 框架。IOBluetooth 是一个 OS X 框架

\n
\n

这已经不再是事实了,Core Bluetooth 不只是iOS 框架,尽管 IOBluetoothmacOS独有的

\n
\n

CoreBluetooth 用于访问低功耗蓝牙 API。IOBluetooth 用于蓝牙经典接口

\n
\n

这也是不正确的,因为核心蓝牙并非专门用于 BLE。

\n

CoreBluetooth 文档指出:

\n
\n

与蓝牙低功耗和 BR/EDR (\xe2\x80\x9cClassic\xe2\x80\x9d) 设备通信。

\n
\n

这看起来很简单;核心蓝牙用于蓝牙通信,包括 BLE 和 Classic。

\n

IOBluetooth 文档指出:

\n
\n

获得对蓝牙设备的用户空间访问。

\n
\n

但这并不是特别有启发性。

\n

在 macOS 10.13+ 上的 CoreBluetooth …

macos bluetooth iobluetooth core-bluetooth

3
推荐指数
1
解决办法
778
查看次数

OS X 10.8上的LightBlue:方法签名不匹配

我正在使用Nickolay Yegorov的LightBlue 端口用于OS X 10.8.导入lightblue模块后,我立即收到以下错误:

Traceback (most recent call last):
  File "commander.py", line 3, in <module>
    import lightblue
  File "/usr/local/lib/python2.7/site-packages/lightblue/__init__.py", line 160, in <module>
    from _lightblue import *
  File "/usr/local/lib/python2.7/site-packages/lightblue/_lightblue.py", line 397, in <module>
    class _AsyncDeviceInquiry(Foundation.NSObject):
TypeError: Error when calling the metaclass bases
    class _AsyncDeviceInquiry does not correctly implement protocol IOBluetoothDeviceInquiryDelegate: the signature for method deviceInquiryComplete:error:aborted: is v@:@iB instead of v@:@iZ
Run Code Online (Sandbox Code Playgroud)

似乎可能存在版本不匹配.这个问题有一个已知的解决方案吗?

python macos bluetooth iobluetooth lightblue

2
推荐指数
1
解决办法
1200
查看次数

Mac OS X /蓝牙:以编程方式禁用简单配对?

开发工具(/ Developer/Applications/Utilities/Bluetooth /)中的Bluetooth Explorer应用程序允许您关闭设备上的简单配对.(运行应用程序,选择菜单项:"实用程序>获取本地设备信息",然后单击"简单配对"选项卡).

第三方应用程序如何执行此操作?

macos bluetooth iobluetooth

1
推荐指数
1
解决办法
1886
查看次数

如何使用 IOBluetooth/CoreBluetooth 的服务请求?

我想要做的是在 Mac 上使用 iPhone 上的 Apple 通知中心服务 (ANCS)。为了让我的 Mac 出现在我 iPhone 的蓝牙设置中,我显然需要使用服务请求。

到目前为止我所尝试的是CBPeripheralManager在我的 Mac 上启动一个,向它添加 ANCS 服务并开始做广告。这似乎不行,因为我的 Mac 没有出现在我 iPhone 的蓝牙设置中。我还尝试过启动CBCentralManager并开始扫描,CBCentralManagerScanOptionSolicitedServiceUUIDsKey密钥中包含 ANCS UUID ,这也不起作用。

有没有人知道如何做到这一点?我花了大量时间观看 WWDC 视频并浏览 Apple 的文档,但除了对“服务请求”的一些模糊提及之外,我找不到它。

谢谢!

macos iobluetooth ios core-bluetooth ancs

1
推荐指数
1
解决办法
2838
查看次数

OSX蓝牙LE外设传输速率很慢

背景资料:

我已经为OSX实现了蓝牙LE外设,它暴露了两个特性(使用CoreBluetooth).一个是可读的,一个是可写的(两者都有指示).我在iOS上实现了一个Bluetooth LE Central,它将从可读特性中读取并写入可写特性.我已将其设置为每次读取特征值时,都会更新该值(以类似于此示例的方式).我通过这种设置获得的传输速率非常缓慢(以大约340 字节 /秒的测量持续速度进行补偿).此速度是实际数据,而不是包括数据包详细信息,ACK等的度量.

问题:

这种持续的速度太慢了.我考虑过两个解决方案:

  1. CoreBluetooth中有一些我错过的参数可以帮助我提高速度.
  2. 我需要使用IOBluetooth类而不是CoreBluetooth来实现自定义蓝牙LE服务.

我相信,我已经用尽了选项1.我没有看到任何其他可以调整的参数.我只限于每封邮件发送20个字节.还有其他任何东西,我在iOS设备上收到有关未知错误,不太可能错误或值"不长"的神秘错误.由于演示项目还指示了一个20字节的MTU,我会接受这可能是不可能的.

所以我留下了选项2.我试图以某种方式修改OSX上蓝牙LE的连接参数,希望能够提高传输速度(通过将最小和最大连接间隔分别设置为20ms和40ms - 如以及每个连接间隔发送多个BT数据包).看起来在IOBluetooth上提供我自己的SDP服务是在OSX上实现这一目标的唯一方法.这个问题是关于如何做到这一点的文档可以忽略不计.

告诉我如何实现我自己的服务(尽管使用deprecate API),但是,它没有解释注册SDP服务所需的参数.所以我想知道:

  1. 我在哪里可以找到这本词典所需的参数?
  2. 如何以提供蓝牙LE服务的方式定义这些参数?
  3. 有没有其他方法可以通过另一个框架(Python库?可以访问蓝牙堆栈的VM中的Linux?在OSX上提供蓝牙LE外设?我想完全避免这种情况.)

macos bluetooth iobluetooth ios

0
推荐指数
1
解决办法
2747
查看次数