調用后,用戶可以選擇將該表單以“新增聯系人”或“添加到已有聯系人”的方式(APP端目前沒有選擇步驟,將直接寫入),寫入手機系統通訊錄,完成手機通訊錄聯系人和聯系方式的增加。
A. 直接添加到通訊錄
add_phone: function(b_touxiang) {
uni.addPhoneContact({
photoFilePath: '' + b_touxiang, //頭像
nickName: '' + _self.show.nickname, //昵稱
lastName: '' + _self.show.lastname, //姓氏
firstName: '' + _self.show.firstname, //名字
remark: '' + _self.show.miaoshu, //備注
mobilePhoneNumber: '' + _self.show.mobile, //手機號
weChatNumber: '' + _self.show.weixinname, //微信號
organization: '' + _self.show.company, //公司
title: '' + _self.show.zhiwei, //職位
workPhoneNumber: '' + _self.show.mobile, //工作電話
workAddressStreet: '' + _self.show.workhome, //工作地址街道
email: '' + _self.show.email, //電子郵件
success: function() {
//console.log('success');
},
fail: function() {
//console.log('fail');
}
});
},
B. 添加到通訊錄的同時還帶有聯系人的頭像
這個地方一定要下載保存聯系人的頭像到本地。
add_phone: function(bphone) {
let filePath = '' + _self.show.touxiang; //頭像
let show_touxiang = filePath; //頭像
//先下載文件
if (filePath) {
uni.showLoading({
title: '下載聯系人頭像中'
});
//先下載文件
uni.downloadFile({
url: encodeURI(filePath), //注意中文文件名的網絡地址需要encodeURI
success(res) {
uni.showLoading({
title: '保存頭像中'
});
//保存文件
uni.saveFile({
tempFilePath: res.tempFilePath,
success: function(res) {
//console.log("bbb",res);
show_touxiang = res.savedFilePath; //頭像
uni.hideLoading();
//添加到通訊錄
uni.addPhoneContact({
photoFilePath: '' + show_touxiang, //頭像
nickName: '' + _self.show.nickname, //昵稱
lastName: '' + _self.show.lastname, //姓氏
firstName: '' + _self.show.firstname, //名字
remark: '' + _self.show.miaoshu, //備注
mobilePhoneNumber: '' + _self.show.mobile, //手機號
weChatNumber: '' + _self.show.weixinname, //微信號
organization: '' + _self.show.company, //公司
title: '' + _self.show.zhiwei, //職位
workPhoneNumber: '' + _self.show.mobile, //工作電話
workAddressStreet: '' + _self.show.workhome, //工作地址街道
email: '' + _self.show.email, //電子郵件
success: function() {
//console.log('success');
},
fail: function() {
//console.log('fail');
}
});
}
});
},
fail() {
}
});
}
},
addPhoneContact的一些參數說明
參數名 類型 必填 說明
photoFilePath String 否 頭像本地文件路徑
nickName String 否 昵稱
lastName String 否 姓氏
middleName String 否 中間名
firstName String 是 名字
remark String 否 備注
mobilePhoneNumber String 否 手機號
weChatNumber String 否 微信號
addressCountry String 否 聯系地址國家
addressState String 否 聯系地址省份
addressCity String 否 聯系地址城市
addressStreet String 否 聯系地址街道
addressPostalCode String 否 聯系地址郵政編碼
organization String 否 公司
title String 否 職位
workFaxNumber String 否 工作傳真
workPhoneNumber String 否 工作電話
hostNumber String 否 公司電話
email String 否 電子郵件
url String 否 網站
workAddressCountry String 否 工作地址國家
workAddressState String 否 工作地址省份
workAddressCity String 否 工作地址城市
workAddressStreet String 否 工作地址街道
workAddressPostalCode String 否 工作地址郵政編碼
homeFaxNumber String 否 住宅傳真
homePhoneNumber String 否 住宅電話
homeAddressCountry String 否 住宅地址國家
homeAddressState String 否 住宅地址省份
homeAddressCity String 否 住宅地址城市
homeAddressStreet String 否 住宅地址街道
homeAddressPostalCode String 否 住宅地址郵政編碼
success Function 否 接口調用成功的回調
fail Function 否 接口調用失敗的回調函數
complete Function 否 接口調用結束的回調函數(調用成功、失敗都會執行)