如何使用iOS上的BluetoothManager.framework私有API发送和接收数据

这些天我正在开展一个项目,我们需要将非MFI蓝牙设备连接到iPhone,并且该设备不支持成为BLE外围设备客户端,因此我们必须在经典蓝牙上执行此操作.

我设法使用BluetoothManager.framework与demo project BeeTee的指南配对并将设备连接到iPhone

但我不知道如何发送和recv数据,我在类转储标头中找不到API.

似乎答案在于这三个结构:BTAccessoryManagerImpl& BTSessionImpl& BTDeviceImpl,但我无法得到它们的定义.

@class NSMutableDictionary;

struct BTSessionImpl { };
struct BTDeviceImpl { };


@interface BluetoothManager : NSObject {
    struct BTAccessoryManagerImpl { } *_accessoryManager;
    BOOL _audioConnected;
    int _available;
    NSMutableDictionary *_btAddrDict;
    NSMutableDictionary *_btDeviceDict;
    struct BTdiscoveryAgentImpl { } *_discoveryAgent;
    struct BTLocalDeviceImpl { } *_localDevice;
    struct BTPairingAgentImpl { } *_pairingAgent;
    BOOL _scanningEnabled;
    BOOL _scanningInProgress;
    unsigned int _scanningServiceMask;
    struct BTSessionImpl *_session; // struct BTSessionImpl { } *_session;

}

+ (int)lastinitError;
+ (id)sharedInstance;

- (struct BTAccessoryManagerImpl *)_accessoryManager; // - (struct BTAccessoryManagerImpl { }*)_accessoryManager;
- (void)_advertisingChanged;
- (BOOL)_attach:(id)arg1;
- (void)_cleanup:(BOOL)arg1;
- (void)_connectabilityChanged;
- (void)_connectedStatusChanged;
- (void)_discoveryStateChanged;
- (BOOL)_onlySensorsConnected;
- (void)_postNotification:(id)arg1;
- (void)_postNotificationWithArray:(id)arg1;
- (void)_powerChanged;
- (void)_removeDevice:(id)arg1;
- (void)_restartScan;
- (void)_scanForServices:(unsigned int)arg1 withMode:(int)arg2;
- (void)_setScanState:(int)arg1;
- (BOOL)_setup:(struct BTSessionImpl*)arg1;
- (void)acceptssp:(int)arg1 forDevice:(id)arg2;
- (id)addDeviceIfNeeded:(struct BTDeviceImpl *)arg1;
- (BOOL)audioConnected;
- (BOOL)available;
- (void)cancelPairing;
- (void)connectDevice:(id)arg1 withServices:(unsigned int)arg2;
- (void)connectDevice:(id)arg1;
- (BOOL)connectable;
- (BOOL)connected;
- (id)connectedDevices;
- (id)connectingDevices;
- (void)dealloc;
- (BOOL)devicePairingEnabled;
- (BOOL)deviceScanningEnabled;
- (BOOL)deviceScanningInProgress;
- (void)enableTestMode;
- (BOOL)enabled;
- (void)endVoiceCommand:(id)arg1;
- (id)init;
- (BOOL)isAnyoneAdvertising;
- (BOOL)isAnyonescanning;
- (BOOL)isdiscoverable;
- (BOOL)isServiceSupported:(unsigned int)arg1;
- (int)localDeviceSupportsService:(unsigned int)arg1;
- (id)pairedDevices;
- (void)postNotification:(id)arg1;
- (void)postNotificationName:(id)arg1 object:(id)arg2 error:(id)arg3;
- (void)postNotificationName:(id)arg1 object:(id)arg2;
- (int)powerState;
- (BOOL)powered;
- (void)resetDeviceScanning;
- (void)scanForConnectableDevices:(unsigned int)arg1;
- (void)scanForServices:(unsigned int)arg1;
- (void)setAudioConnected:(BOOL)arg1;
- (void)setConnectable:(BOOL)arg1;
- (void)setDevicePairingEnabled:(BOOL)arg1;
- (void)setDeviceScanningEnabled:(BOOL)arg1;
- (void)setdiscoverable:(BOOL)arg1;
- (BOOL)setEnabled:(BOOL)arg1;
- (void)setPincode:(id)arg1 forDevice:(id)arg2;
- (BOOL)setPowered:(BOOL)arg1;
- (void)showPowerPrompt;
- (void)startVoiceCommand:(id)arg1;
- (void)unpairDevice:(id)arg1;
- (BOOL)wasDevicediscovered:(id)arg1;

@end

解决方法

在蓝牙连接上读取或写入数据可以通过虚拟文件/ dev / ttys *完成.成功连接到正确的服务后,您需要从MobileBluetooth.framework调用BTDeviceGetComPortForService,它将检索正确的文件路径.使用正确的头文件的完整示例,您将找到 here.

打开文件并读取或写入文件.而已.
要异步读取数据,可能在方法openTty和readCompletionNotification上有look here.

这对我来说是一款越狱的iOS 7 iPhone.我想听听其他人是否成功使用此解决方案.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...