1、 添加模块
2、添加权限
3、添加策略
Android:
"permissionExternalStorage" : {"request" : "none","prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请允许。"},IOS:
"privacyDescription" : {"NSPhotoLibraryUsageDescription" : "上传用户头像保存分享海报","NSPhotoLibraryAddUsageDescription" : "上传用户头像保存分享海报","NSCameraUsageDescription" : "需要开启摄像头使用权限","NSLocationWhenInUseUsageDescription" : "根据客户地理位置推荐最近门店","NSLocationAlwaysUsageDescription" : "根据客户地理位置推荐最近门店","NSMicrophoneUsageDescription" : "获取用户麦克风","NSAppleMusicUsageDescription" : "","NSContactsUsageDescription" : "获取用户通讯录"},
4、小程序需要添加隐私权限 (通讯录)
小程序 -- 微信公众平台 中修改隐私策略
5、保存代码
放到util里面 公用
baocundianhua(name, phone, address) {let _this = thisuni.addPhoneContact({nickName: name,firstName: name,remark: name,mobilePhoneNumber: phone,success: function() {console.log('success');uni.showToast({title: '添加成功',icon: 'success',duration: 2000})},fail: function(e) {console.log(e);uni.showToast({title: '添加失败',icon: 'error',duration: 2000})}});},