Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

API 介绍

MoreCross 提供了一系列 API(mc. 命名空间),覆盖基础能力、界面交互、网络、存储、媒体、设备等开发场景, 帮助开发者调用平台能力,写出体验与原生应用一致的 MoreCross 应用。

调用方式

绝大多数 API 采用 mc.接口名 的形式调用,例如:

mc.showToast({
  title: '操作成功',
})

mc.getSystemInfo({
  success: function (res) {
    console.log(res.brand, res.model)
  },
})

部分 API 会返回一个对象实例(如 InnerAudioContext、VideoContext、SelectorQuery), 需要先用 mc.createXxx / mc.getXxx 创建或获取实例,再调用实例上的方法。

回调约定

需要异步返回结果的 API,统一支持三个回调参数:

参数类型必填说明
successfunction否接口调用成功的回调函数
failfunction否接口调用失败的回调函数
completefunction否接口调用结束的回调函数(成功、失败都会执行)

分类索引