Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Boolean mc.canIUse(String schema)

判断应用的API,回调,参数,组件等是否在当前版本可用。

参数

参数类型默认值必填说明
schemaString是使用 ${API}.${method}.${param}.${option} 或者 ${component}.${attribute}.${option} 方式来调用

返回值

类型说明
Boolean当前版本是否可用

参数说明:

  • ${API} 代表 API 名字
  • ${method} 代表调用方式,有效值为return, success, object, callback
  • ${param} 代表参数或者返回值
  • ${option} 代表参数的可选值或者返回值的属性
  • ${component} 代表组件名字
  • ${attribute} 代表组件属性
  • ${option} 代表组件属性的可选值

示例代码:

// 对象的属性或方法
mc.canIUse('env.USER_DATA_PATH')
mc.canIUse('console.log')
mc.canIUse('BackgroundAudioManager.play')

// mc接口参数、回调或者返回值
mc.canIUse('openBluetoothAdapter')
mc.canIUse('getSystemInfoSync.return.safeArea.left')
mc.canIUse('getSystemInfo.success.screenWidth')
mc.canIUse('showToast.object.image')

// 组件的属性
mc.canIUse('editor')
mc.canIUse('text.selectable')
mc.canIUse('icon.type.waiting')