# uni.makePhoneCall(options) GitCodeGitHub

拨打电话

# makePhoneCall 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS HarmonyOS uni-app x UTS 插件
4.0 4.41 4.63 4.63 4.63 4.61 4.61

注意

# 参数

名称 类型 必填 默认值 兼容性 描述
options MakePhoneCallOptions -
-
名称 类型 必备 默认值 兼容性 描述
phoneNumber string -
需要拨打的电话号码
success (result: MakePhoneCallSuccess) => void -
成功返回的回调函数
fail (result: MakePhoneCallFail) => void -
失败的回调函数
complete (result: any) => void -
结束的回调函数(调用成功、失败都会执行)

# MakePhoneCallFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number -
-
合法值 兼容性 描述
1500601
-
当前设备不支持此功能
1500602
-
无效号码
1500603
-
内部错误
errSubject string -
-
统一错误主题(模块)名称
data any -
-
错误信息中包含的数据
cause Error -
-
源错误信息,可以包含多个错误,详见SourceError
errMsg string -
-

# 参见

# 示例

示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见

扫码体验(手机浏览器跳转到App直达页)

示例

<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="disabled">拨打</button>
      </view>
    </view>
  </view>
</template>
<script lang="uts">
  export default {
    data() {
      return {
        title: 'makePhoneCall',
        disabled: true,
        inputValue: ''
      }
    },
    methods: {
      bindInput: function (e : UniInputEvent) {
        this.inputValue = e.detail.value
        if (this.inputValue.length > 0) {
          this.disabled = false
        } else {
          this.disabled = true
        }
      },
      makePhoneCall: function () {
        uni.makePhoneCall({
          phoneNumber: this.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

名称 类型 必备 默认值 兼容性 描述
errMsg string -
错误信息