Device binding and unbinding

4.1 Functional Overview

When connecting the device for the first time, you need to execute the binding command. According to the status type returned by the binding command, there are authorized binding and unauthorized binding. For authorized binding, you need to enter the verification code displayed on the bracelet to bind successfully. You can bind directly without confirmation. Device unbinding includes connection unbinding and disconnection unbinding. When connected, unbind is when the app sends an unbind command to unbind both parties, and all data on the bracelet will be erased at the same time. When disconnected, the app unilaterally modifies the binding. The status is unbound, and the data on the bracelet will not be erased.

4.2 bind command

Objc:

IDOSetBindingInfoBluetoothModel * model = [[IDOSetBindingInfoBluetoothModel alloc]init];
    [IDOFoundationCommand bindingCommand:model waitForSure:^{
         //The process of binding waiting
    } callback:^(IDO_BIND_STATUS status, int errorCode) {
        if (errorCode == 0) {
        if (status == IDO_BLUETOOTH_BIND_SUCCESS) { 
          //Binding succeeded
        }else if (status == IDO_BLUETOOTH_BINDED) {
         //already bound
        }else if (status == IDO_BLUETOOTH_BIND_FAILED) { 
         //bind failed  
        }else if (status == IDO_BLUETOOTH_NEED_AUTH) { 
         //Authorization binding required
        }else if (status == IDO_BLUETOOTH_REFUSED_BINDED) { 
         //refuse to bind
        }
    }else { 
    //bind failed
    }
}];

//If authorization binding is required, execute the following code
IDOSetBindingInfoBluetoothModel * model = [IDOSetBindingInfoBluetoothModel currentModel];
//Enter the authorization code
model.authCode = authCode;
[IDOFoundationCommand setAuthCodeCommand:model callback:^(int errorCode) {
    if (errorCode == 0) {
      //Authorization binding succeeded
    }else {
      //Authorization binding failed
    }
}];

Swift:

 let model = IDOSetBindingInfoBluetoothModel.init();
IDOFoundationCommand.bindingCommand(model, callback: {(state,errorCode) in
 if errorCode == 0 {
    if state == IDO_BIND_STATUS.BLUETOOTH_BIND_SUCCESS { 
       //Binding succeeded
    }else if state == IDO_BIND_STATUS.BLUETOOTH_BINDED { 
       // already bound
    }else if state == IDO_BIND_STATUS.BLUETOOTH_BIND_FAILED { 
       // bind failed
    }else if state == IDO_BIND_STATUS.BLUETOOTH_NEED_AUTH { 
       // Authorization binding required
    }else if state == IDO_BIND_STATUS.BLUETOOTH_REFUSED_BINDED {
       // refuse to bind
     }
  }else {
     //bind failed
  }
 });

 //If authorization binding is required, execute the following code
let currentModel = IDOSetBindingInfoBluetoothModel.current();
currentModel?.authCode = authCode;
IDOFoundationCommand.setAuthCode(currentModel, callback: {(errorCode) in
     if errorCode == 0 {
           //Authorization binding succeeded             
     }else {
          //Authorization binding failed           
     }
});

4.3 Unbind command

Objc:

/*
In the connection state, this method executes a successful callback, which belongs to the unbinding of both parties, and deletes the bracelet data;
In the disconnected state, the successful callback is executed, the App is unilaterally unbound, and the bracelet data will not be deleted;
*/
[IDOFoundationCommand mandatoryUnbindingCommand:^(int errorCode) {
    if (errorCode == 0) {
       //Unbind successfully
    }else {
       //Unbind failed
    }
 }];

Swift:

 /*
In the connection state, this method executes a successful callback, which belongs to the unbinding of both parties, and deletes the bracelet data;
In the disconnected state, the successful callback is executed, the App is unilaterally unbound, and the bracelet data will not be deleted;
*/
  IDOFoundationCommand.mandatoryUnbindingCommand { (errorCode) in
    if errorCode == 0 {
       //Unbind successfully
    }else {  
       //Unbind failed 
    }
   };

4.4 switch device

Objc:

//The incoming Mac address is the Mac address of the device that has been bound
[IDOFoundationCommand switchDeviceCommand:model.macAddr
                              isMandatory:YES //NO: Only bound devices can be switched, YES: unbound devices can also be switched
                                 callback:^(int errorCode) {
    if (errorCode == 0) {
        /**
        Successfully initialized switch device information
         Bluetooth needs to be reconnected=>YES
         Connection authentication settings=>NO
         */
        [IDOBluetoothManager shareInstance].isReconnect = YES;
        [IDOBluetoothManager shareInstance].isDetectionAuthCode = NO;
        if (!__IDO_CONNECTED__) {//Scan if not connected
            [IDOBluetoothManager startScan];
        }else {//Disconnect if connected, start auto scan connection
           [IDOBluetoothManager cancelCurrentPeripheralConnection];
        }
    }else {
        //Failed to switch
    }
}];

//Listen to the device connection callback, if the connection fails, the switch device fails, and if the connection is successful, execute the following command
/**
If the switch device is connected successfully, the device encryption authorization code needs to be detected. If the current device does not support authentication, the error code 6 will be returned.
Please press Execute to complete the binding operation as normal。
*/
 [IDOFoundationCommand switchDeviceDetectionEncryptionAuthCallback:^(int errorCode) {
     if(errorCode == 0) { //The authentication device is switched successfully

     }else if(errorCode == 6){ //Ordinary device switch successfully
         [IDOFoundationCommand swithOrdinaryDeviceComplete];
     }else if(errorCode == 1041) { 
       //Inconsistent authorization codes => the device is bound by other mobile phones
     }else if(errorCode == 1035) { 
       //Device is not bound
     }else { //failure
     }
 }];

Swift:

//The incoming Mac address is the Mac address of the device that has been bound
IDOFoundationCommand.switchDeviceCommand("", isMandatory: true) { (errorCode) in
    if errorCode == 0 {
        /**
        Successfully initialized switch device information
        Bluetooth needs to be reconnected=>YES
        Connection authentication settings=>NO
        */
        IDOBluetoothManager.shareInstance().isReconnect = true
        IDOBluetoothManager.shareInstance().isDetectionAuthCode = false
        if !IDOBluetoothEngine.shareInstance().managerEngine.isConnected {
            //Scan if not connected
            IDOBluetoothManager.startScan()
        }else {
            //Disconnect if connected, start auto scan connection
            IDOBluetoothManager.cancelCurrentPeripheralConnection()
        }
    }else {
        //Failed to switch
    }
}

//Listen to the device connection callback, if the connection fails, the switch device fails, and if the connection is successful, execute the following command
/**
If the switch device is connected successfully, the device encryption authorization code needs to be detected. If the current device does not support authentication, the error code 6 will be returned.
Please press Execute to complete the binding operation as normal。
*/
 IDOFoundationCommand.switchDeviceDetectionEncryptionAuthCallback { (errorCode) in
    if errorCode == 0 {
        //The authentication device is switched successfully
    }else if errorCode == 6 {
        //Ordinary device switch successfully
        IDOFoundationCommand.swithOrdinaryDeviceComplete()
    }else if errorCode == 1041 {
        //Inconsistent authorization codes => the device is bound by other mobile phones
    }else if errorCode == 1035 {
        //Device is not bound
    }else {
        //failed
    }
}

4.5 Demo Unbind function entry

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 ""