跳到主要内容

CheckFeature API

CheckFeature API

checkFeature(options)

提前检查特定 API 在当前平台是否受支持。SDK 中不存在的 API 会跳过平台通信直接返回失败。

选项:

参数类型必填说明
apiNamestring要检查的 API 名称
successfunction-功能受支持时的回调
failfunction-功能不受支持时的回调
completefunction-完成回调

成功响应:

字段类型说明
supportedtrue功能受支持
status'supported'支持状态
apiNamestring检查的 API 名称

失败响应:

字段类型说明
supportedfalse功能不受支持
statusstring不支持原因
apiNamestring检查的 API 名称
detailstring?详细说明

status 值:

说明
'unknown_api'SDK 中不存在的 API
'version_required'需要更新应用版本
'platform_unsupported'平台不支持
'device_unsupported'设备不支持
'permission_denied'权限被拒绝
TudadaSDK.checkFeature({
apiName: 'startAccelerometerSensor',
success: (res) => {
console.log('支持:', res.apiName);
},
fail: (res) => {
console.log('不支持:', res.status);
if (res.status === 'version_required') {
showUpdatePrompt(); // 游戏自身更新提示
}
},
});

checkFeatureAsync(apiName)

基于 Promise 的功能检查。无论支持与否,均通过 resolve 返回。

参数:

参数类型必填说明
apiNamestring要检查的 API 名称

返回值:

字段类型说明
supportedboolean功能是否受支持
statusstring支持状态或不支持原因
apiNamestring检查的 API 名称
detailstring?详细说明(不支持时)
const result = await TudadaSDK.checkFeatureAsync('startAccelerometerSensor');
if (result.supported) {
TudadaSDK.startAccelerometerSensor();
} else {
console.log('不支持原因:', result.status);
}