Native Method

Last Updated on : 2023-10-12 08:00:23download

This topic describes additional methods that can be used to integrate Tuya’s panel SDK into your native app.

Navigate to schedule page of panel

The schedule feature implemented by TYSdk.native.gotoDpAlarm does not support the raw type of data points (DPs) that are specified by dpId.

API name

TYSdk.native.gotoDpAlarm()

API description

Navigates to the schedule page of a panel.

Request parameter

Parameter Data type Description Required
category string The type of schedule. Yes
repeat number
  • 0: repeats the schedule.
  • 1: does not repeat the schedule.
Yes
data data The data of the DP that applies the schedule. Yes

Sample request

/**
 * @desc navigates to the schedule page of a panel.
 * @param {string} category: customizes the type of schedule.
 * @param {string | number} dpId: returns the DP that applies the schedule.
 * @param {string} dpName: the name of the DP.
 * @param {string[] | number[]} rangeKeys: the keys that specify the value range of the DP.
 * @param {string[]} rangeValues: The details of the DP value range. The details are the values that match the keys specified by `rangeKeys`.
 */

const dpId = TYSdk.device.getDpIdByCode(dpCode);
const dpName = Strings.getDpLang(dpCode);
const category = "schedule";
TYSdk.native.gotoDpAlarm({
  category,
  repeat: 0, // 0: repeats the schedule. 1: does not repeat the schedule.
  data: [
    {
      dpId,
      dpName,
      selected: 0, // The index of the default DP value.
      rangeKeys: [true, false],
      rangeValues: [dpValue1, dpValue2], // The array of DP values of string type.
    },
  ],
});

Native Method Native Method

Navigate to device details page

API name

TYSdk.native.showDeviceMenu()

API description

Navigates to the device details page.

Sample request

/**
 * @desc navigates to the device details page.
 */

TYSdk.native.showDeviceMenu();

Determine support for Bluetooth

API name

TYSdk.native.isBTCapabilitySupport()

API description

Checks whether the current device supports Bluetooth.

Request parameter

Parameter Data type Description Required
deviceId string The device ID. Yes

Sample request

TYSdk.native.isBTCapabilitySupport('YOUR_DEVICE_ID')
  .then(data => console.log('data: ', data))
  .catch(err => console.log('err: ', err));

Get Bluetooth details of device

API name

TYSdk.native.getBTInfo()

API description

Returns information about device’s Bluetooth by device ID.

Request parameter

Parameter Data type Description Required
deviceId string The device ID. Yes

Sample request

TYSdk.native.getBTInfo('YOUR_DEVICE_ID')
  .then(data => console.log('data: ', data))
  .catch(err => console.log('err: ', err));

Open dialog box for pairing Bluetooth device for Android

API name

TYSdk.native.createBTbond()

API description

Opens the dialog box for pairing a Bluetooth device based on the MAC address of the device. This feature applies to Android mobile devices only.

Request parameter

Parameter Data type Description Required
mac string The MAC address of the Bluetooth device. Yes

Sample request

TYSdk.native.createBTbond('YOUR_DEVICE_MAC')
  .then(data => console.log('data: ', data))
  .catch(err => console.log('err: ', err));

Remove connection to Bluetooth device for Android

API name

TYSdk.native.removeBTbond()

API description

Removes a connection to a Bluetooth device based on the MAC address of the device. This feature applies to Android mobile devices only.

Request parameter

Parameter Data type Description Required
mac string The MAC address of the Bluetooth device. Yes

Sample request

TYSdk.native.removeBTbond('YOUR_DEVICE_MAC')
  .then(data => console.log('data: ', data))
  .catch(err => console.log('err: ', err));

Open system settings page for iOS

API name

TYSdk.native.jumpToSettingPage()

API description

Navigates to the system settings page. This feature applies to iOS mobile devices only.

Request parameter

None

Sample request

TYSdk.native.jumpToSettingPage();