本文實例講述了微信小程序實現添加手機聯系人功能。分享給大家供大家參考,具體如下:
1、效果展示
2、關鍵代碼
1)WXML文件
<view bindlongtap="phoneNumTap">{{phoneNum}}</view>
2)JS文件
Page({ data:{ phoneNum:'12345678901'//測試用的號碼,并非真實號碼 }, // 長按號碼響應函數 phoneNumTap:function(){ var that=this; // 提示呼叫號碼還是將號碼添加到手機通訊錄 wx.showActionSheet({ itemList: ['呼叫','添加聯系人'], success:function(res){ if(res.tapIndex===0){ // 呼叫號碼 wx.makePhoneCall({ phoneNumber: that.data.phoneNum, }) }else if(res.tapIndex==1){ // 添加到手機通訊錄 wx.addPhoneContact({ firstName: 'test',//聯系人姓名 mobilePhoneNumber: that.data.phoneNum,//聯系人手機號 }) } } }) }})
3)WXSS文件
view{ color: blue; padding: 15px; border-bottom: 1px solid gainsboro;}
3、完整實例代碼點擊此處本站下載。
希望本文所述對大家微信小程序開發有所幫助。
新聞熱點
疑難解答