uni-app做拨打电话功能 但是区分ios和安卓 两个机型出的效果不一样
前端页面代码
这里是在一个循环体内 从每一条数据中拿到对应的电话 实现点击拨打
<view @click="callphone(item.phone)">{{item.phone}}</view>
js代码
callphone:function(phone){
// 可以先打印看是否拿到传进来的电话
console.log(phone);
// uni.getSystemInfoSync()是获取信息同步对应接口
const res = uni.getSystemInfoSync();
// ios系统默认有个模态框
if(res.platform == 'ios'){
uni.makePhoneCall({
phoneNumber:phone,
success(){
console.log('拨打成功了');
},
fail() {
console.log('拨打失败了');
}
})
} else {
// 安卓手机手动设置一个showActionSheet
uni.showActionSheet({
itemList: [phone,'呼叫'],
success:function(res){
console.log(res);
if(res.tapIndex==1){
uni.makePhoneCall({
phoneNumber: phone,
})
}
}
})
}
},