Bluetooth Management Library

2.1 Functional Overview

When you apply an unconnected bound device, you need to create a view controller that implements the SDK bluetooth proxy. Scan peripheral devices, the agent will return the device collection, display it in the list, select the device that needs to be connected, after the connection is successful, it will return the device information and whether the device is in OTA mode, if the connection fails, there will be an error callback. The default scan signal filter parameter is 80, and the automatic scan connection timeout is 20 seconds. The Bluetooth management library (IDOBluetooth) depends on the Bluetooth protocol library (IDOBlueProtocol), so before using the Bluetooth management library, import the Bluetooth protocol library first.

2.2 Scanning connection flow chart

png

2.3 Bluetooth initialization

Objc:

[IDOBluetoothManager shareInstance].rssiNum = 100;
[IDOBluetoothManager shareInstance].delegate = self;

Swift:

 IDOBluetoothManager.shareInstance()?.rssiNum = 100;
 IDOBluetoothManager.shareInstance()?.delegate = self;

2.4 Parameter Description

parameters illustrate Remarks
timeout Auto scan connection timeout period default 20
rssiNum set scan filter signal Default value 80
isIntervalScan Whether to start the timeout interval scan Default yes
isReconnect Whether a reconnection mechanism is required default yes
autoScanInterval Set the scan interval default 10s
isMandatoryManual Force switch to manual mode to scan connections Add a device that is currently bound to a device
scanMode Bluetooth scan device mode readonly
state Bluetooth management connection status readonly
errorCode Bluetooth connection error code readonly
manualConnectTotalTime Total time spent manually clicking connected devices readonly
autoConnectTotalTime Total duration of auto scan to successfully connected devices readonly

2.5 basic method

Objc:

//start scanning
[IDOBluetoothManager startScan];
//refresh bluetooth proxy
[IDOBluetoothManager refreshDelegate];
//stop scanning
[IDOBluetoothManager stopScan];
//Connect the device
[IDOBluetoothManager connectDeviceWithModel:model];
//Disconnects the current peripheral device
[IDOBluetoothManager cancelCurrentPeripheralConnection];

Swift:

 //start scanning
 IDOBluetoothManager.startScan();
 //refresh bluetooth proxy
 IDOBluetoothManager.refreshDelegate();
 //stop scanning
 IDOBluetoothManager.stopScan();
 //Connect the device
 IDOBluetoothManager .connectDevice(with: model as? IDOPeripheralModel); 
 //Disconnects the current peripheral device
 IDOBluetoothManager.cancelCurrentPeripheralConnection();

2.6 proxy method

Objc:

<IDOBluetoothManagerDelegate>
- (BOOL)bluetoothManager:(IDOBluetoothManager *)manager
           centerManager:(CBCentralManager *)centerManager
    didConnectPeripheral:(CBPeripheral *)peripheral
               isOatMode:(BOOL)isOtaMode
{
    //Device connection successful callback
    return YES;
}

- (void)bluetoothManager:(IDOBluetoothManager *)manager
              allDevices:(NSArray<IDOPeripheralModel *> *)allDevices
              otaDevices:(NSArray<IDOPeripheralModel *> *)otaDevices
{
   //Scanning devices returns the device collection callback in real time
}

- (void)bluetoothManager:(IDOBluetoothManager *)manager
          didUpdateState:(IDO_BLUETOOTH_MANAGER_STATE)state
{
    //Scan connection status callback
}

- (void)bluetoothManager:(IDOBluetoothManager *)manager
  connectPeripheralError:(NSError *)error
{
   //Scan connection error callback
}

Swift:

IDOBluetoothManagerDelegate
func bluetoothManager(_ manager: IDOBluetoothManager!, connectPeripheralError error: Error!) {
        //Scan connection error callback
};

func bluetoothManager(_ manager: IDOBluetoothManager!, didUpdate state: IDO_BLUETOOTH_MANAGER_STATE) {
      //Scan connection status callback
};

func bluetoothManager(_ manager: IDOBluetoothManager!, allDevices: [IDOPeripheralModel]!, otaDevices: [IDOPeripheralModel]!) {
      //Scanning devices returns the device collection callback in real time  
};

func bluetoothManager(_ manager: IDOBluetoothManager!, center centerManager: CBCentralManager!, didConnect peripheral: CBPeripheral!, isOatMode isOtaMode: Bool) -> Bool {
     //Device connection successful callback
    return true;
};

2.7 Bluetooth notification

1.IDOBluetoothConnectStateNotifyName Bluetooth scan connection status monitoring notification name. Generally, this notification is monitored globally. When the Bluetooth status changes, a notification is thrown and the corresponding UI interaction is modified.。

2.IDOBluetoothConnectErrorNotifyName Bluetooth scan connection error monitoring notification name. Generally, this notification is monitored globally. When a Bluetooth error occurs, a notification is thrown, and the corresponding UI interaction is modified.。

3.IDOBluetoothOtaModeNotifyName The Bluetooth connection bracelet is the name of the OTA mode monitoring notification. Generally, this notification is monitored globally. When the current bracelet is found to be in OTA mode after the Bluetooth connection, a notification is thrown, and the bracelet upgrade operation is performed according to the business。

Copyright © 2015-2020 IDO. All rights reserved. all right reserved,powered by GitbookModify Date: 2023-12-18 10:04:13

results matching ""

    No results matching ""