uniApp 实现微信小程序一键保存通讯录、一键拨打、一键导航、一键分享功能

9人浏览 / 0人评论 / 添加收藏

1、一键保存通讯录
      //  保存联系人到通讯录
  saveContactToPhone() {
   let _this = this
  
   uni.addPhoneContact({
    // 昵称
    nickName: "小旗下",
    // 姓
    lastName: "刘",
    // 名
    firstName:"娜娜",
                
                   //手机号
    mobilePhoneNumber: "188888888888",
                   //手邮箱
    email:"@163qq.com",
    // addressStreet: "辽宁省沈阳市",
    // 微信号
    weChatNumber: "188888888888",
    // workAddressCountry: '中国大陆',
    // 公司地址
    workAddressStreet: "沈阳市XXXXXXXXXXXXXX",
    success: function() {
     uni.showToast({
      title: '添加成功',
      icon: 'success',
      duration: 2000
     })
    },
    fail: function() {
     uni.showToast({
      title: '已取消保存',
      icon: 'error',
      duration: 2000
     })
     uni.getSetting({
      success(res) {
          
       if (!res.authSetting['scope.addPhoneContact']) {
        uni.authorize({
         scope: 'addPhoneContact',
         success() {
          // 用户已经同意小程序使用通讯地址簿
          _this.saveContactToPhone()
         },
         fail() {

          uni.showModal({
           title: '提示',
           content: '您已拒绝通讯录授权,是否确定打开设置开通权限!',
           // showCancel: false,
           confirmText: '确定',
           confirmColor: '#FB9046',
           success: function(res) {
            if (res.confirm) {
             _this.openSetting()
            }
           }
          });

         }
        })
       }
      }
     })
    }
   });


  },
  // 授权
  openSetting() {
   uni.openSetting({
    success(res) {
     console.log(res.authSetting)
    }
   })
  },
2、一键拨打电话
byMakePhoneCall() {
   uni.makePhoneCall({
    phoneNumber: "1888888888", // 电话号码
    success: function() {
     console.log('拨号成功');
    },
    fail: function(err) {
     console.error('拨号失败:', err);
    }
   });

},
3、一键导航
// 一键导航
byNavigation() {
  
 wx.openLocation({
           //纬度
  latitude: "",
           //经度
  longitude: "",
           //地址名称
  name: "",
           //详细地址
  address: "",
           //缩放比例
  scale: 14
 })
},
4、一键分享功能
<button  class="bluetext"  open-type="share">
  <view>一键分享</view>
</button>

       //分享给微信好友
 onShareAppMessage() {
  return {
   title: title,
   path: '/pages/index/main?displayname=' +this.displayname,

  }

}

 

全部评论