my.addPhoneContact lets users add a contact to their phone—either by filling a form (create new or add to existing) or by passing contact data from your Mini Program. All contact fields are optional; only the ones you provide are used.
<button onclick="addContact()">Add to phone contacts</button>
function addContact() {
if (!my.canIUse("addPhoneContact")) {
my.alert({
title: "Client version too low",
content: "my.addPhoneContact() requires a higher version.",
});
return;
}
my.addPhoneContact({
nickName: "Baking July",
lastName: "Last",
middleName: "Middle",
firstName: "First",
remark: "This is remarks",
mobilePhoneNumber: "13000000000",
success: (res) => {
my.alert({ content: "addPhoneContact response: " + JSON.stringify(res) });
},
fail: (res) => {
my.alert({ content: "addPhoneContact failed: " + JSON.stringify(res) });
},
});
}
Object type with the following attributes. All contact fields are optional.
| Property | Type | Required | Description |
|---|---|---|---|
photoFilePath | String | No | Local file path of avatar. |
nickName | String | No | Nickname. |
lastName | String | No | Surname. |
middleName | String | No | Middle name. |
firstName | String | No | First name. |
remark | String | No | Remarks. |
mobilePhoneNumber | String | No | Cell number. |
homePhoneNumber | String | No | Home phone. |
workPhoneNumber | String | No | Work phone. |
homeFaxNumber | String | No | Home fax. |
workFaxNumber | String | No | Work fax. |
hostNumber | String | No | Company phone number. |
addressCountry | String | No | Country in contact address. |
addressState | String | No | Province in contact address. |
addressCity | String | No | City in contact address. |
addressStreet | String | No | Street in contact address. |
addressPostalCode | String | No | Postcode in contact address. |
workAddressCountry | String | No | Country in work address. |
workAddressState | String | No | Province in work address. |
workAddressCity | String | No | City in work address. |
workAddressStreet | String | No | Street in work address. |
workAddressPostalCode | String | No | Postcode in work address. |
homeAddressCountry | String | No | Country in home address. |
homeAddressState | String | No | Province in home address. |
homeAddressCity | String | No | City in home address. |
homeAddressStreet | String | No | Street in home address. |
homeAddressPostalCode | String | No | Postcode in home address. |
organization | String | No | Company. |
title | String | No | Job title. |
email | String | No | Email. |
url | String | No | Website. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion. |
Success: Callback receives an object with success: true.
Failure: Callback receives an error object. Common cases:
| Error | Description |
|---|---|
11 | User cancelled the operation. |
2 | Call failure; detail includes more information. |