1. 记录日常采坑

刚开始是这样写的

<view class="" @tap="call()">
		联系客服
</view>
	call(){
			let phone = '‭123456789‬'
			  uni.makePhoneCall({
				phoneNumber:phone,
				success:function(){
					console.log('拨打电话成功');
				},
				fail() {
					console.log('打电话失败了');
				}
			})
			}

安卓手机可以拨打,但是苹果手机没反应,有的说是电话号码必须是字符串,不能有空格……试了都不行啊。

2. 最后把电话号码放在call()的参数中,可以了竟然

<view class="" @tap="call('123456789')">
		联系客服
</view>
call(phone) {
			console.log('传入的电话',phone);
			//uni.makePhoneCall({
				// 	  phoneNumber:phone,
				// 	success(){
				// 		console.log('拨打成功了');
				// 	},
				// 	fail() {
				// 		console.log('拨打失败了');
				// 	}
				// })
			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,
				            })
				          }
				        }
				      })
			}

			}

测试OK,还有就是安卓手机打电话,直接跳转到拨打电话号码界面了,苹果手机是有个模态框,确认后才会拨打电话。

在这里插入图片描述

3. 其它

APP端打包上线记得在manifest.json中勾选拨打电话的权限。
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐