CheckFeature API
CheckFeature API
checkFeature(options)
提前检查特定 API 在当前平台是否受支持。SDK 中不存在的 API 会跳过平台通信直接返回失败。
选项:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
apiName | string | ✅ | 要检查的 API 名称 |
success | function | - | 功能受支持时的回调 |
fail | function | - | 功能不受支持时的回调 |
complete | function | - | 完成回调 |
成功响应:
| 字段 | 类型 | 说明 |
|---|---|---|
supported | true | 功能受支持 |
status | 'supported' | 支持状态 |
apiName | string | 检查的 API 名称 |
失败响应:
| 字段 | 类型 | 说明 |
|---|---|---|
supported | false | 功能不受支持 |
status | string | 不支持原因 |
apiName | string | 检查的 API 名称 |
detail | string? | 详细说明 |
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 返回。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
apiName | string | ✅ | 要检查的 API 名称 |
返回值:
| 字段 | 类型 | 说明 |
|---|---|---|
supported | boolean | 功能是否受支持 |
status | string | 支持状态或不支持原因 |
apiName | string | 检查的 API 名称 |
detail | string? | 详细说明(不支持时) |
const result = await TudadaSDK.checkFeatureAsync('startAccelerometerSensor');
if (result.supported) {
TudadaSDK.startAccelerometerSensor();
} else {
console.log('不支持原因:', result.status);
}