uniapp实现拨打电话跳转手机拨号界面 (ios和安卓通用)

效果展示:左边为安卓系统展示,右边为ios系统展示

代码:

toPhone(){
  uni.makePhoneCall({
    phoneNumber: "10086", //要拨打的手机号
    success: (res) => {
      // console.log("调用成功")
    },
    fail: (res) => {
      // console.log('调用失败!')
    }
  })
},

api解析:uni.makePhoneCall(OBJECT)  拨打电话

OBJECT 参数说明:

参数名 类型 必填 说明
phoneNumber String 需要拨打的电话号码
success Function 接口调用成功的回调
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

uniapp官方文档链接:https://uniapp.dcloud.net.cn/api/system/phone.html#makephonecall


拓展:点击弹出电话号码列表,选择其中一个电话号进行拨打

效果展示:

代码:

toPhone() {
  const phoneList = ["10086","10010","10000"]
  uni.showActionSheet({
    itemList: phoneList,  //电话列表
    success: function(res) {
      if (res.tapIndex !== undefined) {
        uni.makePhoneCall({
          phoneNumber: phoneList[res.tapIndex],
          success: function() {
            //console.log('拨打电话成功');
          },
          fail: function() {
            //console.log('拨打电话失败');
          }
        });
      }
    }
  });
}

api解析:uni.showActionSheet(OBJECT)     从底部向上弹出操作菜单

OBJECT参数说明:

参数 类型 必填 说明 平台差异说明
title String 菜单标题 App、H5、支付宝小程序、钉钉小程序、微信小程序 3.4.5+(仅真机有效)
alertText String 警示文案(同菜单标题) 微信小程序(仅真机有效)
itemList Array<String> 按钮的文字数组 微信、百度、抖音小程序数组长度最大为6个
itemColor HexColor 按钮的文字颜色,字符串格式,默认为"#000000" App-iOS、飞书小程序不支持
popover Object 大屏设备弹出原生选择按钮框的指示区域,默认居中显示 App-iPad(2.6.6+)、H5(2.9.2)
success Function 接口调用成功的回调函数,详见返回参数说明
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

popover 值说明(仅App生效):

类型 说明
top Number 指示区域坐标,使用原生 navigationBar 时一般需要加上 navigationBar 的高度
left Number 指示区域坐标
width Number 指示区域宽度
height Number 指示区域高度

success返回参数说明:

参数 类型 说明
tapIndex Number 用户点击的按钮,从上到下的顺序,从0开始

uniapp官方文档链接: https://uniapp.dcloud.net.cn/api/ui/prompt.html#showactionsheet

扫描二维码关注公众号,回复: 17244706 查看本文章

猜你喜欢

转载自blog.csdn.net/weixin_73318685/article/details/134810651