ios - iOS 上的 IOBluetooth/使用其 Mac 地址连接到设备?

标签 ios bluetooth core-bluetooth iobluetooth

在工作中,我被赋予了使命 :) 移植一个连接到设备以执行操作的 Android 库(由于 NDA,我不能说更多)。 Android 代码使用 getRemoteDevice(macAddress)createRfcommSocketToServiceRecord 基本上跳过整个配对机制,然后“按原样”发送字节。这在 iOS 上可行吗?有没有这种程度的“肮脏”:-)

最佳答案

如果是蓝牙2.1就很简单了。您还可以创建套接字。例如:

EASession *session = [[EASession alloc] initWithAccessory:accessory
                                   forProtocol:PROTOCOL_STRING];
if (session) {

    [[session inputStream] setDelegate:self];
    [[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [[session inputStream] open];

    [[session outputStream] setDelegate:self];
    [[session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [[session outputStream] open];
}

但是,正如@Paulw11 提到的,您需要通过 MFI 程序。

蓝牙 LE 有很大不同。它没有 socket 。您只能以服务和特征进行操作。

顺便说一句,您不能仅通过使用其 MAC 地址连接到 BLE 设备。您首先需要使用其服务 UUID 扫描此设备:

[_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:kScanServiceUUID]] options:options];

只有在那之后连接到它的 CBPeripheral。

更新: 至于蓝牙 2.1 中的“基本上跳过整个配对机制”,我猜你不能在没有用户的情况下进行配对。 有一种方法向用户显示对话框,他可以选择他想要配对的设备,但这就是我能找到的全部:

- (void)showBluetoothAccessoryPickerWithNameFilter:(NSPredicate *)predicate completion:(EABluetoothAccessoryPickerCompletion)completion

Displays an alert that allows the user to pair the device with a Bluetooth accessory.

与蓝牙 2.1 不同,在低功耗蓝牙中您根本不需要配对。

关于ios - iOS 上的 IOBluetooth/使用其 Mac 地址连接到设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325809/

相关文章:

python - Twisted 和 PyBluez 一起工作?

ios - iBeacon 开始在应用程序上转换广告确实进入了后台

ios - iBeacon : didRangeBeacons not being called

ios - 我可以使用 AVAudioRecorder 将录音流发送到服务器吗?

iOS:添加数组以创建动态单元格

android - 如何断开蓝牙连接 (HTC Desire)

macos - Core Bluetooth 和 IOBluetooth 有什么区别

ios - 使用Parse作为我的BaaS制作社交照片共享应用程序

ios - 如何获得与方向相关的屏幕高度和宽度?

java - InputStream.read() 在我的缓冲区中丢失或添加了一个值 - 这是怎么回事?