Device binding/unbinding

Attributes

isBinding

Whether it is in the binding (in the binding, switching devices will be restricted)

method

bind(osVersion:onDeviceInfo:onFuncTable:completion:)

0 Binding failed 1 Binding successful 2 Already bound 3 Authorization code required for binding 4 Binding refused 5 Binding error device 6 Authorization code verification failed 7 Unbinding 8 Binding failed (failed to obtain the menu) 9 Binding Failed (failed to obtain device information)

bind(osVersion:onDeviceInfo:onFuncTable:onEncryptedAuthData:completion:)

Same as above, with an optional onEncryptedAuthData callback that receives encrypted authorization data.

Optional: Use only when function table getSupportEncryptedAuth is true, and your product needs to bind the same device across phones when the device does not support re-binding, or needs to associate authorization data with an account. Otherwise omit this callback and ignore getEncryptedAuthData / setEncryptedAuthData below.

IDOEncryptedAuthData fields:

Field Type Description
authData Byte array Authorization data (usually 12 bytes; unsigned values 0–255)
encryptedVersion Int Encryption version (0: legacy, 0x10: new)
authLength Int Authorization data length

JSON helpers (cloud / account storage):

Platform Serialize Parse
iOS jsonString() → String? IDOEncryptedAuthData(jsonString:)
Android toJsonString() → String IDOEncryptedAuthData.fromJsonString(json)

Cloud JSON keys: auth_data (int array 0–255), encrypted_version, auth_length.

cancelBind()

Unbind

appMarkBindResult(success: Bool)

The APP delivers the binding result (only used by devices that require the app to confirm the binding result)

unbind(macAddress:isForceRemove:completion:)

Initiate unbinding

macAddress: device Mac address isForceRemove: forcefully delete the device, delete it even if the device does not respond

setAuthCode(code:osVersion:completion:)

Send authorization pairing code (only for supported devices)

code pairing code osVersion: system version (take the major version number)

setEncryptedAuthData(macAddress:data:completion:)

Set encrypted authorization data. Optional: only for devices that support encrypted auth, and only when you need cross-phone binding of the same device or account association. Call this before connecting the device. After it succeeds, the App must persist the device as bound so that IDOBridgeDelegate.checkDeviceBindState returns true for that Mac on connect (see IDOBridgeDelegate).

Parameter Type Description
macAddress String Device Mac address
data IDOEncryptedAuthData Encrypted authorization data (see table above)

getEncryptedAuthData(macAddress:completion:)

Get encrypted authorization data cached by the SDK on this phone. Optional: same applicability as above; callbacks nil / null when none exists. For cross-phone flows, use account-side cloud data as the source of truth; this API is for reading the local cache on the same phone.

Parameter Type Description
macAddress String Device Mac address

Example

Swift:

// Binding (existing API, unchanged)
sdk.cmd.bind(osVersion: 15) { devInfo in
       print("1 Obtained device information - battLevel: \(devInfo.battLevel)")
   } onFuncTable: { ft in
       print("1Get the menu - alexaSetEasyOperateV3: \(ft.alexaSetEasyOperateV3)")
   } completion: { status in
       switch status {
       case .failed:
           print("\(status)")
           // Binding failed
       case .successful:
           // Binding successful
           print("\(status)")
           print("2 Obtained device information - battLevel: \(sdk.device.battLevel)")
           print("2 Get the function table - alexaSetEasyOperateV3: \(sdk.funcTable.alexaSetEasyOperateV3)")
       case .binded:
           print("\(status)")
       case .needAuth:
           print("\(status)")
       case .refusedBind:
           print("\(status)")
       case .wrongDevice:
           print("\(status)")
       case .authCodeCheckFailed:
           print("\(status)")
       case .canceled:
           print("\(status)")
       case .failedOnGetFunctionTable:
           print("\(status)")
       case .failedOnGetDeviceInfo:
           print("\(status)")
       case .timeout:
           print("\(status)")
       case .agreeDeleteDeviceData:
           print("\(status)")
       case .denyDeleteDeviceData:
           print("\(status)")
       case .timeoutOnNewAccount:
           print("\(status)")
       case .needConfirmByApp:
           print("\(status)")
           Cmds.sendBindResult(isSuccess: true).send { rs in
               if case .success(_) = rs {
                   print("success:")
                   sdk.cmd.appMarkBindResult(success: true)
               }else {
                   print("failure")
                   sdk.cmd.appMarkBindResult(success: false)
               }
           }
       }
   }

// ---------- Optional: cross-phone / account-linked encrypted auth ----------
// Phone A signs in as account A and binds device A → store auth JSON with the account in the cloud
// → Phone B: setEncryptedAuthData → persist local "bound" → then BLE connect
// → IDOBridgeDelegate.checkDeviceBindState must return true for that Mac
// Cloud JSON example:
// {"auth_data":[175,131,218,123,174,147,71,60,244,117,179,182],"encrypted_version":0,"auth_length":12}

// Phone A: bind and receive auth data; serialize to JSON and upload with the account
sdk.cmd.bind(osVersion: 15,
             onDeviceInfo: { _ in },
             onFuncTable: { _ in },
             onEncryptedAuthData: { authData in
                 // Upload JSON string with the account (keys: auth_data / encrypted_version / auth_length)
                 if let json = authData.jsonString() {
                     print("cloud auth JSON: \(json)")
                 }
             },
             completion: { _ in })

// Same phone (optional): read SDK local cache
sdk.cmd.getEncryptedAuthData(macAddress: macAddress) { cached in
    guard let cached = cached else { return }
    print("authLength: \(cached.authLength), json: \(cached.jsonString() ?? "")")
}

// Phone B: (1) set auth from cloud JSON (2) persist local bound flag (3) then connect
let authJson = #"{"auth_data":[175,131,218,123,174,147,71,60,244,117,179,182],"encrypted_version":0,"auth_length":12}"#
guard let saved = IDOEncryptedAuthData(jsonString: authJson) else { return }
sdk.cmd.setEncryptedAuthData(macAddress: macAddress, data: saved) { ok in
    guard ok else { return }
    // After set succeeds, mark local bind so checkDeviceBindState returns true
    UserDefaults.standard.setBind(macAddress, isBind: true, device: deviceModel)
    sdk.ble.connect(device: deviceModel)
}

// Unbind
sdk.cmd.unbind(macAddress: macAddress, isForceRemove: true, completion: { rs in
     if rs {
         // Unbinding successful
     } else {
         // Unbinding failed
     }
})

Kotlin:

// Bind (existing API, unchanged)
  sdk.cmd.bind(15, {
   println("Get device information state$it");
}, {
   println("Get the function table functableinterface state$it");
}, {
   closeProgressDialog()
   when (it) {
     IDOBindStatus.SUCCESSFUL -> {
       toast("bind ok")
       //save bind info
       SPUtil.putAValue(bind_key + device?.macAddress, true)
     }
     IDOBindStatus.FAILED,
     IDOBindStatus.BINDED,
     IDOBindStatus.NEEDAUTH,
     IDOBindStatus.REFUSEDBIND -> {
       println("bind failed: ${it.name}")
       toast("bind failed: ${it.name}")
     }

     else -> {

     }
   }
})

// ---------- Optional: cross-phone / account-linked encrypted auth ----------
// Phone B: setEncryptedAuthData → persist local bound → then connect; checkDeviceBindState must return true
// Cloud JSON example:
// {"auth_data":[175,131,218,123,174,147,71,60,244,117,179,182],"encrypted_version":0,"auth_length":12}

// Phone A: bind and receive auth data; serialize to JSON and upload with the account
sdk.cmd.bind(15, { }, { }, { authData ->
  // Upload JSON string with the account (keys: auth_data / encrypted_version / auth_length)
  println("cloud auth JSON: ${authData.toJsonString()}")
}, { })

// Same phone (optional): read SDK local cache
sdk.cmd.getEncryptedAuthData(macAddress) { cached ->
  cached ?: return@getEncryptedAuthData
  println("authLength=${cached.authLength}, json=${cached.toJsonString()}")
}

// Phone B: (1) set auth from cloud JSON (2) persist local bound flag (3) then connect
val authJson = """{"auth_data":[175,131,218,123,174,147,71,60,244,117,179,182],"encrypted_version":0,"auth_length":12}"""
val saved = IDOEncryptedAuthData.fromJsonString(authJson) ?: return
sdk.cmd.setEncryptedAuthData(macAddress, saved) { ok ->
  if (!ok) return@setEncryptedAuthData
  // After set succeeds, mark local bind so checkDeviceBindState returns true
  FunctionUtils.saveBoundDevice(device!!)
  IDOSDK.instance().ble.connect(device)
}

// Unbind
sdk.cmd.unbind(macAddress = macAddress, isForceRemove = true, completion = { rs ->
   if (rs) {
     // Unbinding successful
   } else {
     // Unbinding failed
   }
})
Copyright © 2023-2024 IDO. All rights reserved. all right reserved,powered by Gitbook修改日期: 2026-10-21 04:26:43

results matching ""

    No results matching ""