我正在开发一款需要连接到非BLE蓝牙脉搏血氧仪设备才能下载数据的应用。此应用程序不会提交给应用程序商店,所以在这个阶段,我并不担心它被拒绝。
这是我提出的一些基本代码,它基于BeeTee示例,用于连接脉搏血氧仪。
#import "MDBluetoothManager.h"
#import "BTMViewController.h"
@interface BTMViewController () <MDBluetoothObserverProtocol>
{
IBOutlet UILabel * statusLabel;
}
@property (nonatomic, strong) MDBluetoothDevice * connectedBluetoothDevice;
- (void)receivedBluetoothNotification:(MDBluetoothNotification)bluetoothNotification;
@end
@implementation BTMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[MDBluetoothManager sharedInstance] registerObserver:self];
if (![[MDBluetoothManager sharedInstance] bluetoothIsPowered])
{
//NSLog(@"Bluetooth not powered on!");
[[MDBluetoothManager sharedInstance] turnBluetoothOn];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
statusLabel.text = @"Scanning ...";
[[MDBluetoothManager sharedInstance] startScan];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[MDBluetoothManager sharedInstance] endScan];
[self.connectedBluetoothDevice disconnect];
[super viewWillDisappear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Bluetooth Connectivity
- (void)receivedBluetoothNotification:(MDBluetoothNotification)bluetoothNotification
{
BOOL isPowered = [[MDBluetoothManager sharedInstance] bluetoothIsPowered];
switch (bluetoothNotification)
{
case MDBluetoothAvailabilityChangedNotification:
{
//NSLog(@"Bluetooth availability changed to %@", [NSNumber numberWithBool:isPowered]);
if (isPowered)
{
[[MDBluetoothManager sharedInstance] startScan];
}
break;
}
case MDBluetoothPowerChangedNotification:
//NSLog(@"Bluetooth power changed to %@", [NSNumber numberWithBool:isPowered]);
break;
case MDBluetoothDeviceDiscoveredNotification:
{
//NSLog(@"Bluetooth device discovered");
NSArray* detectedBluetoothDevices = [[MDBluetoothManager sharedInstance] discoveredBluetoothDevices];
for (int index=0; index<detectedBluetoothDevices.count; index++)
{
self.connectedBluetoothDevice = [detectedBluetoothDevices objectAtIndex:index];
//NSLog(@"Bluetooth Device: %@ (%@)", bluetoothDevice.name, bluetoothDevice.address);
if ([self.connectedBluetoothDevice.name isEqualToString:@"SpO2"])
{
NSLog(@"Pairing with Pulse Oximeter");
[statusLabel performSelectorOnMainThread:@selector(setText:) withObject:@"Pairing with Pulse Oximeter" waitUntilDone:NO];
self.connectedBluetoothDevice.pin = @"7762";
[self.connectedBluetoothDevice connect];
[[MDBluetoothManager sharedInstance] endScan];
}
}
break;
}
case MDBluetoothDeviceConnectSuccessNotification:
{
NSLog(@"Connected to Pulse Oximeter!");
statusLabel.text = @"Connected to Pulse Oximeter!";
}
break;
case MDBluetoothDeviceRemovedNotification:
//NSLog(@"Bluetooth device removed");
break;
default:
//NSLog(@"Unknown Bluetooth notification!");
break;
}
}
@end
是否有人知道如何启动数据传输以使用私有API下载所有数据?
或
有没有人有另一种方法连接到非BLE设备下载数据?
谢谢