Back to Uni App

Make Phone Call

docs/api/make-phone-call.md

2.3.36.8 KB
Original Source
<!-- ## uni.makePhoneCall(options) @makephonecall -->

::: sourceCode

uni.makePhoneCall(options) @makephonecall

GitCode: https://gitcode.com/dcloud/uni-api/tree/alpha/uni_modules/uni-makePhoneCall

GitHub: https://github.com/dcloudio/uni-api/tree/alpha/uni_modules/uni-makePhoneCall

:::

拨打电话

makePhoneCall 兼容性

Web微信小程序AndroidiOSiOS uni-app x UTS 插件HarmonyOSHarmonyOS uni-app x UTS 插件
4.04.414.634.634.634.614.61

::: warning 注意

:::

参数

名称类型必填默认值兼容性描述
optionsMakePhoneCallOptions-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -

options 的属性描述

名称类型必备默认值兼容性描述
phoneNumberstring-Web: 4.0; 微信小程序: 4.41; Android: 4.63; iOS: 4.63; iOS uni-app x UTS 插件: 4.63; HarmonyOS: 4.61; HarmonyOS uni-app x UTS 插件: 4.61需要拨打的电话号码
success(result: MakePhoneCallSuccess) => void-Web: 4.0; 微信小程序: 4.41; Android: 4.63; iOS: 4.63; iOS uni-app x UTS 插件: 4.63; HarmonyOS: 4.61; HarmonyOS uni-app x UTS 插件: 4.61成功返回的回调函数
fail(result: MakePhoneCallFail) => void-Web: 4.0; 微信小程序: 4.41; Android: 4.63; iOS: 4.63; iOS uni-app x UTS 插件: 4.63; HarmonyOS: 4.61; HarmonyOS uni-app x UTS 插件: 4.61失败的回调函数
complete(result: any) => void-Web: 4.0; 微信小程序: 4.41; Android: 4.63; iOS: 4.63; iOS uni-app x UTS 插件: 4.63; HarmonyOS: 4.61; HarmonyOS uni-app x UTS 插件: 4.61结束的回调函数(调用成功、失败都会执行)

MakePhoneCallFail 的属性值 @makephonecallfail-values

名称类型必备默认值兼容性描述
errCodenumber-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
errSubjectstring-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -统一错误主题(模块)名称
dataany-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -错误信息中包含的数据
causeError-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -源错误信息,可以包含多个错误,详见SourceError
errMsgstring-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -

errCode 的属性描述

合法值兼容性描述
1500601Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -当前设备不支持此功能
1500602Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -无效号码
1500603Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -内部错误

参见

示例

示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见 ::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/make-phone-call/make-phone-call

appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/make-phone-call/make-phone-call

示例

vue
<template>
  <view>
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <view class="uni-hello-text uni-center">请在下方输入电话号码</view>
      <input class="input uni-common-mt" type="number" name="input" @input="bindInput" />
      <view class="uni-btn-v uni-common-mt">
        <button @tap="makePhoneCall" type="primary" :disabled="data.disabled">拨打</button>
      </view>
    </view>
  </view>
</template>
<script setup lang="uts">
  type DataType = {
    disabled: boolean;
    inputValue: string;
  }

  const title = ref('makePhoneCall')
  const data = reactive({
    disabled: true,
    inputValue: ''
  } as DataType)

  const bindInput = (e : UniInputEvent) => {
    data.inputValue = e.detail.value
    if (data.inputValue.length > 0) {
      data.disabled = false
    } else {
      data.disabled = true
    }
  }

  const makePhoneCall = () => {
    uni.makePhoneCall({
      phoneNumber: data.inputValue,
      success: () => {
        console.log("成功拨打电话")
      },
      fail: (err) => {
        console.log(err.errCode)
        uni.showToast({
          title: '错误码:' + err.errCode.toString(),
          icon: "error"
        })
      }
    })
  }

</script>

<style>
  .input {
    height: 60px;
    line-height: 60px;
    font-size: 39px;
    border-bottom: 1px solid #E2E2E2;
    text-align: center;
  }
</style>

:::

通用类型

GeneralCallbackResult

名称类型必备默认值兼容性描述
errMsgstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -错误信息