Bluetooth Device Pairing

Last Updated on : 2024-08-22 03:27:24download

Bluetooth device search and pairing applies to Bluetooth Low Energy (LE), Bluetooth mesh, combo device, and beacon.

Bluetooth type Description Example
Bluetooth LE A point-to-point connection is created between a Bluetooth or Bluetooth LE device and a mobile phone. Body fat scales, wrist-worn trackers, thermostats, electric toothbrushes, and smart locks
Bluetooth mesh Enable many-to-many (m:m) device communications over a mesh network released by Bluetooth SIG. Cool white lights (C), cool and warm white lights (CW), white and colored lights (RGBCW), sockets, sensors, and other sub-devices
Combo devices Devices that support both Bluetooth and other protocols, such as Wi-Fi and Bluetooth LE combo, can be paired over Bluetooth. Bluetooth mesh gateways, IP cameras (IPCs), and Wi-Fi and Bluetooth combo devices
Beacon Beacon is a broadcast protocol built on top of Bluetooth LE. Lights, fans, remotes, and body fat scales

The ThingSmartBusinessExtensionKitBLEExtra component offers more features than the ThingSmartBLEManager. If you are still using ThingSmartBLEManager, please refer to Bluetooth Devices and Bluetooth Mesh.

Functional description

The following Bluetooth features are supported:

  • Device pairing
    • Scan and discover devices.
    • Pair devices.
  • Device management
    • Check the current device networking status.
    • Connect to devices.
    • Operate and remotely control devices.
    • Unbind devices.
  • Firmware OTA update
    • Check firmware versions.
    • Update firmware over the air.

Permissions

In iOS 13, Apple has replaced the original field NSBluetoothPeripheralUsageDescription that is used to request Bluetooth permissions with the field NSBluetoothAlwaysUsageDescription. The new field is added to info.plist.

<key>NSBluetoothAlwaysUsageDescription</key>
    <string></string>

<key>NSBluetoothPeripheralUsageDescription</key>
    <string></string>

Compatibility with iOS 12

For iOS 12, [[ThingSmartActivator sharedInstance] currentWifiSSID] cannot return a valid Wi-Fi service set identifier (SSID).

To query Wi-Fi information in Xcode 10, certain permissions are required. Set Access Wi-Fi Information to ON at Xcode > [Project Name] > Targets > [Target Name] > Capabilities.

Bluetooth Device Pairing
## Pairing process
AppBizBundle SDKDeviceCloudEnter pairing mode.Start searching for devices.Get device information.Return device information.alt[Search for devices]Request device activation.Start activation.Activate with the cloud.Activated successfully.Return the list of activated devices.Return the list of activated devices.alt[Activation and pairing]AppBizBundle SDKDeviceCloudBluetooth Device Activation and Pairing

You can tailor the Bluetooth features as needed. If Bluetooth is not required, there is no need to depend on ThingBLEHomeManager, ThingBLEInterfaceImpl, and ThingBLEMeshInterfaceImpl.

Register the pairing type

When the device pairing service is initialized, register the pairing type.

Device type Pairing type Model
Bluetooth LE or combo device ThingSmartActivatorTypeBle ThingSmartActivatorTypeBleModel
Bluetooth mesh ThingSmartActivatorTypeSigMesh ThingSmartActivatorTypeSigMeshModel
Beacon ThingSmartActivatorTypeBeacon ThingSmartActivatorTypeBeaconModel
/// Initialize network configuration types
/// @param typeList Network configuration types
- (void)registerWithActivatorList:(NSArray<ThingSmartActivatorTypeModel *>*)typeList;

Parameter description

Parameters Description
typeList The list of pairing types.

Get a token

The SDK gets a pairing token from the cloud before it can start the pairing process. The token is valid for 10 minutes and expires immediately after the device is paired. A new token must be generated if the device needs to be paired again.

API description

- (void)getTokenWithHomeId:(long long)homeId
                   success:(ThingSuccessString)success
                   failure:(ThingFailureError)failure;

Parameter description

Parameters Description
homeId The ID of the home with which the device is bound.
success The success callback. A pairing token is returned.
failure The failure callback. An error message is returned.

Start searching

Pass in the registered typeList to start searching.

API description

/// Start searching
/// @param typeList Network configuration types
- (void)startSearch:(NSArray <ThingSmartActivatorTypeModel *>*)typeList;

Parameter description

Parameters Description
typeList The list of pairing types.

Stop searching

API description

/// Stop searching
/// @param typeList Network configuration types
/// @param clearCache Whether to clear the cache
- (void)stopSearch:(NSArray <ThingSmartActivatorTypeModel *>*)typeList clearCache:(BOOL)clearCache;

Parameter description

Parameters Description
typeList The list of pairing types.
clearCache Specifies whether to clear the cache search result.

Device search callback

After the Bluetooth device is discovered, the callback returns the device information. If the operation fails, the callback returns the error message.

API description

/// Device search callback
/// @param service Search instance
/// @param type Network configuration type
/// @param device Discovered device
/// @param errorModel Error callback
- (void)activatorService:(id<ThingSmartActivatorSearchProtocol>)service
            activatorType:(ThingSmartActivatorTypeModel *)type
             didFindDevice:(nullable ThingSmartActivatorDeviceModel *)device
                     error:(nullable ThingSmartActivatorErrorModel *)errorModel;

Parameter description

Parameters Description
service The pairing service.
type The pairing type.
device The discovered device. The device model is returned on success. nil is returned on failure.
errorModel This model is not returned when no Bluetooth device is discovered or when the search times out.

Activate a device

API description

/// Activate devices with a single network configuration type
/// @param type Network configuration type
/// @param deviceList Devices to be activated
- (void)startActive:(ThingSmartActivatorTypeModel *)type deviceList:(NSArray<ThingSmartActivatorDeviceModel *>*)deviceList;

Parameter description

Parameters Description
type The pairing type.
deviceList The list of devices to be activated. Currently, only one device is supported.

Stop activation

API description

/// Stop activating devices
/// @param typeList Array of network configuration types
/// @param clearCache Whether to clear the cache
- (void)stopActive:(NSArray <ThingSmartActivatorTypeModel *>*)typeList clearCache:(BOOL)clearCache;

Parameter description

Parameters Description
typeList The pairing type.
clearCache Specifies whether to clear the cache search result.

Activation callback

API description

// Device network configuration result callback
/// @param service Device network configuration implementation object
/// @param type Network configuration type
/// @param devices Devices being configured
/// @param errorModel Error encountered during network configuration
- (void)activatorService:(id<ThingSmartActivatorActiveProtocol>)service
           activatorType:(ThingSmartActivatorTypeModel *)type
       didReceiveDevices:(nullable NSArray<ThingSmartActivatorDeviceModel *> *)devices
                   error:(nullable ThingSmartActivatorErrorModel *)errorModel;

Parameter description

Parameters Description
service The pairing service.
type The pairing type.
devices The activated device.
errorModel This model is returned if pairing fails or times out. nil is returned on success.

Scan for Wi-Fi networks

When the following error codes are returned for the failure of combo device pairing, you can use this method to scan for and select a Wi-Fi network and then call the pairing restart method to continue the pairing process.

This method requires the baseline version of the firmware built into the target device to be v3.6.0 or later.

Error codes Description
ThingSmartActivatorDiscoveryErrorResumeConfigInfoError Wrong pairing information.
ThingSmartActivatorDiscoveryErrorResumeRouterNotFound Router is not found.
ThingSmartActivatorDiscoveryErrorResumeRouterConnectFailed Failed to connect to the router.
ThingSmartActivatorDiscoveryErrorResumeDHCPError Failed to get the DHCP-assigned IP address.

API description

- (void)scanWifiList:(ThingSmartActivatorScanWifiParam *)param
       activatorType:(ThingSmartActivatorType)activatorType
             success:(void(^)(NSArray<ThingSmartActivatorScanWifiModel *> *list))success
             failure:(void(^)(NSError * _Nullable error))failure;

Parameter description

Parameters Description
param The request parameter for Wi-Fi network scan.
activatorType The pairing type.
success The list of discovered Wi-Fi networks.
failure This model is returned if the operation fails. nil is returned on success.

Restart pairing

When the following error codes are returned for the failure of combo device pairing, you can use this method to restart the pairing process after a Wi-Fi network is selected again. If the failure is caused by a wrong Wi-Fi password, you can restart pairing after the user enters the correct password.

This method requires the baseline version of the firmware built into the target device to be v3.6.0 or later.

Error codes Description
ThingSmartActivatorDiscoveryErrorResumeConfigInfoError Wrong pairing information.
ThingSmartActivatorDiscoveryErrorResumeRouterNotFound Router is not found.
ThingSmartActivatorDiscoveryErrorResumeRouterConnectFailed Failed to connect to the router.
ThingSmartActivatorDiscoveryErrorResumeDHCPError Failed to get the DHCP-assigned IP address.
ThingSmartActivatorDiscoveryErrorResumeWrongPassword Wrong password.

API description

/// Restore Wi-Fi network configuration
/// @param param Restore network configuration parameters
/// @param activatorType Network configuration type
/// @param success Success block
/// @param failure Failure block
- (void)resumeConfigWifi:(ThingSmartActivatorResumeConfigWiFiParam *)param
           activatorType:(ThingSmartActivatorType)activatorType
                 success:(void(^)(void))success
                 failure:(void(^)(ThingSmartActivatorErrorModel * _Nullable error))failure;

Parameter description

Parameters Description
param The request parameter for pairing restart.
activatorType The pairing type.
success The success callback.
errorModel The failure callback.

Error codes

ThingSmartActivatorErrorModel is returned if pairing fails or times out.

@interface ThingSmartActivatorErrorModel : NSObject
@property (nonatomic, strong) ThingSmartActivatorDeviceModel *deviceModel;
@property (nonatomic) NSError *error;
@end

ThingSmartActivatorDiscoveryError includes the definition of error codes. The following table lists the common error codes.

Error codes Description
ThingSmartActivatorDiscoveryErrorTimeout Pairing timeout.
ThingSmartActivatorDiscoveryErrorDeviceAlreadyBound Strong binding error. The device is already bound with a user. Pairing can work only after the device is unbound from the current user.
ThingSmartActivatorDiscoveryErrorAPPUnsupportProduct The app used for pairing is not bound with the product.
ThingSmartActivatorDiscoveryErrorTokenExpired Token expired.
ThingSmartActivatorDiscoveryErrorGuestNotSupportStrongBind A guest account is not allowed to pair a device of strong binding.
ThingSmartActivatorDiscoveryErrorBleScanExpired The device has exited pairing mode.
ThingSmartActivatorDiscoveryErrorResumeConfigInfoError Wrong pairing information. In this case, you can scan for Wi-Fi networks and restart pairing after a Wi-Fi network is selected again. See the example code.
ThingSmartActivatorDiscoveryErrorResumeRouterNotFound Router is not found. In this case, you can scan for Wi-Fi networks and restart pairing after a Wi-Fi network is selected again. See the example code.
ThingSmartActivatorDiscoveryErrorResumeWrongPassword Wrong password. In this case, you can restart pairing after the user enters the correct password. See the example code.
ThingSmartActivatorDiscoveryErrorResumeRouterConnectFailed Failed to connect to the router. In this case, you can scan for Wi-Fi networks and restart pairing after a Wi-Fi network is selected again. See the example code.
ThingSmartActivatorDiscoveryErrorResumeDHCPError DHCP parsing error. In this case, you can scan for Wi-Fi networks and restart pairing after a Wi-Fi network is selected again. See the example code.

Example

Search for a Bluetooth device

Swift:

class BleScanModeTableViewController: UIViewController {

    var deviceList:[ThingSmartActivatorDeviceModel] = []

    private var typeModel: ThingSmartActivatorTypeBleModel = {
        let type = ThingSmartActivatorTypeBleModel()
        type.type = ThingSmartActivatorType.ble
        type.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorType.ble)
        type.timeout = 120
        if let currentHome = Home.current {
            type.spaceId = currentHome.homeId
        } else {
            assert((Home.current != nil),"Home cannot be nil, need to create a Home")
        }
        return type
    }()

    private var sigModel: ThingSmartActivatorTypeSigMeshModel = {
        let type = ThingSmartActivatorTypeSigMeshModel()
        type.type = ThingSmartActivatorType.sigMesh
        type.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorType.sigMesh)
        type.timeout = 120
        if let currentHome = Home.current {
            type.spaceId = currentHome.homeId
        } else {
            assert((Home.current != nil),"Home cannot be nil, need to create a Home")
        }
        return type
    }()

    private var beaconModel: ThingSmartActivatorTypeBeaconModel = {
        let type = ThingSmartActivatorTypeBeaconModel()
        type.type = ThingSmartActivatorType.beacon
        type.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorType.beacon)
        type.timeout = 120
        return type
    }()

    lazy var discovery: ThingSmartActivatorDiscovery = {
        let discovery = ThingSmartActivatorDiscovery()
        discovery.register(withActivatorList: [self.typeModel,self.sigModel,self.beaconModel])
        discovery.setupDelegate(self)
        discovery.loadConfig()
        if let currentHome = Home.current {
            discovery.currentSpaceId(currentHome.homeId)
        } else {
            assert((Home.current != nil),"Home cannot be nil, need to create a Home")
        }
        return discovery
    }()

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)

        stopConfiguring()
    }

    @IBAction func searchTapped(_ sender: UIBarButtonItem) {
        discovery.startSearch([self.typeModel,self.sigModel,self.beaconModel])

        SVProgressHUD.show(withStatus: NSLocalizedString("Searching", comment: ""))

    }

    // MARK: - Private method
    private func stopConfiguring() {
        if !isSuccess {
            SVProgressHUD.dismiss()
        }

        discovery.stopSearch([self.typeModel,self.sigModel,self.beaconModel], clearCache: true)
        discovery.stopActive([self.typeModel,self.sigModel,self.beaconModel], clearCache: true)
        discovery.removeDelegate(self)
    }
}

// MARK: - ThingSmartActivatorSearchDelegate
extension BleScanModeTableViewController: ThingSmartActivatorSearchDelegate {
    func activatorService(_ service: ThingSmartActivatorSearchProtocol, activatorType type: ThingSmartActivatorTypeModel, didFindDevice device: ThingSmartActivatorDeviceModel?, error errorModel: ThingSmartActivatorErrorModel?) {

        if var device = device {
            if device.deviceModelType == ThingSearchDeviceModelTypeBle {

            } else if device.deviceModelType == ThingSearchDeviceModelTypeSigMeshSubDevice {

            } else if device.deviceModelType == ThingSearchDeviceModelTypeBeacon {

            }
            deviceList.append(device)
        }
    }

}

Objective-C:

- (void)scanBleDevice {
    ThingSmartActivatorTypeBleModel *bleModel  = [[ThingSmartActivatorTypeBleModel alloc] init];
    bleModel.type = ThingSmartActivatorTypeBle;
    bleModel.scanType = ThingBluetoothScanTypeNoraml;
    bleModel.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorTypeBle);
    bleModel.spaceId = [ThingSmartActivatorLinkTool getSpaceId];
    bleModel.timeout = 120;

    ThingSmartActivatorTypeSigMeshModel *sigModel  = [[ThingSmartActivatorTypeSigMeshModel alloc] init];
    sigModel.type = ThingSmartActivatorTypeSigMesh;
    sigModel.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorTypeSigMesh);
    sigModel.spaceId =[ThingSmartActivatorLinkTool getSpaceId];
    sigModel.timeout = 120;

    ThingSmartActivatorTypeBeaconModel *beaconModel = [[ThingSmartActivatorTypeBeaconModel alloc] init];
    beaconModel.type = ThingSmartActivatorTypeBeacon;
    beaconModel.typeName = NSStringFromThingSmartActivatorType(ThingSmartActivatorTypeBeacon);
    beaconModel.timeout = 120;

    [self.typeList addObject:bleModel];
    [self.typeList addObject:sigModel];
    [self.typeList addObject:beaconModel];

    [self.discovery registerWithActivatorList:self.typeList];
    [self.discovery setupDelegate:self];

    /// start search
    [self.discovery startSearch:self.typeList];

}

/// Device search callback, multiple times if multiple devices are searched for
- (void)activatorService:(id<ThingSmartActivatorSearchProtocol>)service activatorType:(ThingSmartActivatorTypeModel *)type didFindDevice:(ThingSmartActivatorDeviceModel *)device error:(ThingSmartActivatorErrorModel *)errorModel {

    if (errorModel) {
        [self _connectWifiError:errorModel];
        return;
    }

    if (device) {
        [self _handleDevice:device];
    }
}

- (void)_handleDevice:(ThingSmartActivatorDeviceModel *)deviceModel {
    /// Device Type
    switch(deviceModel.deviceModelType){
      case ThingSearchDeviceModelTypeBle: {
         ThingSmartActivatorTypeBleModel *bleModel = (ThingSmartActivatorTypeBleModel *)[self.discovery activatorTypeModelWith:ThingSmartActivatorTypeBle];
         [self startActive:bleModel device:deviceModel];
      }
        break;
      case ThingSearchDeviceModelTypeBleWifi:{
         ThingSmartActivatorTypeBleModel *bleModel = (ThingSmartActivatorTypeBleModel *)[self.discovery activatorTypeModelWith:ThingSmartActivatorTypeBle];
         [self startActive:bleModel device:deviceModel];
      }
        break;
      case ThingSearchDeviceModelTypeBeacon:{
        ThingSmartActivatorTypeBeaconModel *beaconModel = (ThingSmartActivatorTypeBeaconModel *)[self.discovery activatorTypeModelWith:ThingSmartActivatorTypeBeaconModel];
         [self startActive:beaconModel device:deviceModel];
      }
        break;
      case ThingSearchDeviceModelTypeSigMeshSubDevice:{
        ThingSmartActivatorTypeSigMeshModel *sigModel = (ThingSmartActivatorTypeSigMeshModel *)[self.discovery activatorTypeModelWith:ThingSmartActivatorTypeSigMesh];
         [self startActive:sigModel device:deviceModel];
      }
        break;
    }
}

- (ThingSmartActivatorDiscovery *)discovery {
    if (!_discovery) {
        _discovery = [[ThingSmartActivatorDiscovery alloc] init];
    }
    return _discovery;
}

Pair a Bluetooth LE device

Bluetooth LE devices can only be added serially.

Swift:

func startConfiguring() {
        discovery.startActive(bleModel, deviceList: [deviceMode])
}

extension BleScanModeTableViewController: ThingSmartActivatorActiveDelegate {
    func activatorService(_ service: ThingSmartActivatorActiveProtocol, activatorType type: ThingSmartActivatorTypeModel, didReceiveDevices devices: [ThingSmartActivatorDeviceModel]?, error errorModel: ThingSmartActivatorErrorModel?) {
        if (errorModel != nil) {
            SVProgressHUD.showError(withStatus: NSLocalizedString("Failed to Activate BLE Device", comment: ""))
            return
        }

        if (devices!.count > 0) {
            let device = devices?.first
            let name = device?.name ?? NSLocalizedString("Unknown Name", comment: "Unknown name device.")
            SVProgressHUD.showSuccess(withStatus: NSLocalizedString("Successfully Added \(name)", comment: "Successfully added one device."))
        }
    }
}

Objective-C:

- (void)startActive:(ThingSmartActivatorTypeModel *)type device:(ThingSmartActivatorDeviceModel *)device {
     [self.discovery startActive:bleModel deviceList:@[device]];
}

- (void)activatorService:(id<ThingSmartActivatorActiveProtocol>)service
           activatorType:(ThingSmartActivatorTypeModel *)type
       didReceiveDevices:(nullable NSArray<ThingSmartActivatorDeviceModel *> *)devices
                   error:(nullable ThingSmartActivatorErrorModel *)errorModel {
     if (devices && devices.count > 0) {
         // handle devices
     }
}

Pair a combo device

Combo devices can only be added serially.

For combo devices with firmware baseline version v3.6.0 or later, if the pairing failure is caused by the wrong password, you can restart pairing after the user enters the correct password.

Swift:

func startConfiguring() {
        typeModel.ssid = ssidTextField.text ?? ""
        typeModel.password = ssidTextField.text ?? ""
        discovery.startActive(typeModel, deviceList: [deviceMode])
}

extension BleScanModeTableViewController: ThingSmartActivatorActiveDelegate {
    func activatorService(_ service: ThingSmartActivatorActiveProtocol, activatorType type: ThingSmartActivatorTypeModel, didReceiveDevices devices: [ThingSmartActivatorDeviceModel]?, error errorModel: ThingSmartActivatorErrorModel?) {
        if let errorModel = errorModel {
            let code = errorModel.error

            SVProgressHUD.showError(withStatus: NSLocalizedString("Failed to Activate BLE Device", comment: ""))
            return
        }

        if let devices = devices {
            let device = devices.first
            var successDevice: ThingSmartActivatorDeviceModel?

            self.searchDeviceList.forEach { obj in
                if device!.isEqual(toDevice: obj) {
                    successDevice = obj
                }
            }

            successDevice?.deviceStatus = ThingSearchDeviceStatusNetwork
            tableview.reloadData()
        }
}

Objective-C:

- (void)startActive:(ThingSmartActivatorTypeModel *)type device:(ThingSmartActivatorDeviceModel *)device {
     ThingSmartActivatorTypeBleModel *bleModel = (ThingSmartActivatorTypeBleModel *)type;

     bleModel.ssid = selectSsid;
     bleModel.password = selectPassword;
     [self.discovery startActive:type deviceList:@[device]];
}

- (void)activatorService:(id<ThingSmartActivatorActiveProtocol>)service
           activatorType:(ThingSmartActivatorTypeModel *)type
       didReceiveDevices:(nullable NSArray<ThingSmartActivatorDeviceModel *> *)devices
                   error:(nullable ThingSmartActivatorErrorModel *)errorModel {

     NSInteger code = errorModel.error.code;
    if (code == ThingSmartActivatorDiscoveryErrorResumeWrongPassword) {
        /// Prompts the user that the password is wrong, re-enter the password
        ThingSmartActivatorResumeConfigWiFiParam *wifiParam = [self getwifiInfo];

        // Resume activate
        [self.discovery resumeConfigWifi:wifiParam activatorType:self.typeModel.type success:^{

        } failure:^(ThingSmartActivatorErrorModel * _Nullable error) {
            ThingLogDebug(@"[LinkModeAP] ret:%ld", error.error.code);
        }];
        return;

    }
    else if (code == ThingSmartActivatorDiscoveryErrorResumeRouterNotFound || code == ThingSmartActivatorDiscoveryErrorResumeConfigInfoError || code == ThingSmartActivatorDiscoveryErrorResumeRouterConnectFailed || code == ThingSmartActivatorDiscoveryErrorResumeDHCPError) {
        /// Scan the list of surrounding WiFi and reactivate the network after selection
        [self.discovery scanWifiList:scanWifiParam
                       activatorType:ThingSmartActivatorTypeBle
                             success:^(NSArray<ThingSmartActivatorScanWifiModel *> * _Nonnull list) {
            if (list.count == 0) {
                return;
            }

        ThingSmartActivatorResumeConfigWiFiParam *wifiParam = [self getwifiInfo:list];
        [self.discovery resumeConfigWifi:wifiParam activatorType:self.typeModel.type success:^{

        } failure:^(ThingSmartActivatorErrorModel * _Nullable error) {
            ThingLogDebug(@"[LinkModeAP] ret:%ld", error.error.code);
        }];

        } failure:^(NSError * _Nullable error) {
        }];
        return;
    }

    if (devices && devices.count > 0) {
        /// handle devices
    }
}

Pair a Bluetooth mesh device

If the app has discovered multiple Bluetooth mesh devices, it can pair them all at once.

Swift:

func startConfiguring() {
        discovery.startActive(typeModel, deviceList: [sigModel])
}

extension BleScanModeTableViewController: ThingSmartActivatorActiveDelegate {
    func activatorService(_ service: ThingSmartActivatorActiveProtocol, activatorType type: ThingSmartActivatorTypeModel, didReceiveDevices devices: [ThingSmartActivatorDeviceModel]?, error errorModel: ThingSmartActivatorErrorModel?) {
        if let errorModel = errorModel {
            let code = errorModel.error

            SVProgressHUD.showError(withStatus: NSLocalizedString("Failed to Activate BLE Device", comment: ""))
            return
        }

        if let devices = devices {
            let device = devices.first
            var successDevice: ThingSmartActivatorDeviceModel?

            self.searchDeviceList.forEach { obj in
                if device!.isEqual(toDevice: obj) {
                    successDevice = obj
                }
            }

            successDevice?.deviceStatus = ThingSearchDeviceStatusNetwork
            tableview.reloadData()
        }
}

Objective-C:

- (void)startActive:(ThingSmartActivatorTypeModel *)type device:(ThingSmartActivatorDeviceModel *)device {
     [self.discovery startActive:type deviceList:@[device]];
}

- (void)activatorService:(id<ThingSmartActivatorActiveProtocol>)service
           activatorType:(ThingSmartActivatorTypeModel *)type
       didReceiveDevices:(nullable NSArray<ThingSmartActivatorDeviceModel *> *)devices
                   error:(nullable ThingSmartActivatorErrorModel *)errorModel {
     if (devices && devices.count > 0) {
        // handle devices
     }
}

Pair a beacon device

If the app discovered multiple beacon devices, it can pair them all at once.

Swift:

func startConfiguring() {
        discovery.startActive(typeModel, deviceList: [beaconModel])
}

extension BleScanModeTableViewController: ThingSmartActivatorActiveDelegate {
    func activatorService(_ service: ThingSmartActivatorActiveProtocol, activatorType type: ThingSmartActivatorTypeModel, didReceiveDevices devices: [ThingSmartActivatorDeviceModel]?, error errorModel: ThingSmartActivatorErrorModel?) {
        if let errorModel = errorModel {
            let code = errorModel.error

            SVProgressHUD.showError(withStatus: NSLocalizedString("Failed to Activate BLE Device", comment: ""))
            return
        }

        if let devices = devices {
            let device = devices.first
            var successDevice: ThingSmartActivatorDeviceModel?

            self.searchDeviceList.forEach { obj in
                if device!.isEqual(toDevice: obj) {
                    successDevice = obj
                }
            }

            successDevice?.deviceStatus = ThingSearchDeviceStatusNetwork
            tableview.reloadData()
        }
}

Objective-C:

- (void)startActive:(ThingSmartActivatorTypeModel *)type device:(ThingSmartActivatorDeviceModel *)device {
     [self.discovery startActive:type deviceList:@[device]];
}

- (void)activatorService:(id<ThingSmartActivatorActiveProtocol>)service
           activatorType:(ThingSmartActivatorTypeModel *)type
       didReceiveDevices:(nullable NSArray<ThingSmartActivatorDeviceModel *> *)devices
                   error:(nullable ThingSmartActivatorErrorModel *)errorModel {
     if (devices && devices.count > 0) {
        // handle devices
     }
}