uniapp【App端】调用手机自带短信功能发送短信,打电话,获取本地通讯录
1、配置(修改了manifest配置信息,要重新打包自定义基座,并卸载手机上的安装包重新运行)
2、发短信,拨打电话
// 发短信 sendMsg(phoneNumber) { //#ifdef APP-PLUS plus.messaging.TYPE_SMS; var msg = plus.messaging.createMessage(plus.messaging.TYPE_SMS); msg.to = [phoneNumber]; msg.body = ''; plus.messaging.sendMessage(msg); // #endif //#ifdef H5 window.location.href = `sms:${phoneNumber}` // #endif }, //拨打电话 callPhone(phoneNumber) { uni.makePhoneCall({ phoneNumber, }) }
3、获取本地联系人 官方文档:https://uniapp.dcloud.net.cn/api/system/contact.html#addphonecontact
// 获取本地联系人 created() { //#ifdef APP-PLUS this.getLocalContact() //#endif }, computed:{ contactList(){ return this.localContact.filter(item=>{ return (item.realName.includes(this.searchValue)||item.phone.includes(this.searchValue)) }) } }, methods: { getLocalContact() { let type = plus.contacts.ADDRESSBOOK_PHONE plus.contacts.getAddressBook( type, success => { success.find([], res => { this.localContact = res.map(item => { return { realName: item.displayName, phone: item.phoneNumbers[0].value } }) }, err => { } ) }, error => { console.log(error); }) } }