【问题标题】:How to transfer data from bluetooth device to iPhone using bluetoothmanager.framework如何使用 bluetoothmanager.framework 将数据从蓝牙设备传输到 iPhone
【发布时间】:2015-08-17 13:50:09
【问题描述】:

我正在开发一个需要连接到非 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 设备以下载其数据?

谢谢

【问题讨论】:

    标签: ios iphone bluetooth


    【解决方案1】:

    对于通过Serial Port Profile 传输数据,Apple 需要由MFi 证书处理的身份验证。我怀疑这很容易做到。

    但欢迎对这个开放主题做出任何贡献!

    【讨论】:

      猜你喜欢
      • 2012-07-18
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2012-03-24
      相关资源
      最近更新 更多