- SDK Version: 34
- Platforms(Android/iOS/web/all): only Android
- “expo-contacts”: “^8.0.0”,
I’ve implemented a function to add a contacts to the device.
I ask for permissions as WRITE_CONTACTS and READ_CONTACTS
This is how I create a contact:
const random = Math.floor(Math.random() * 100) + 1; // we don't care about ID to save
const phoneDict = {
id: '0' + random,
label: '',
number: item.phone,
countryCode :'',
digits : '',
isPrimary: true
}
const emailDict = {
id: '1' + random,
email : item.email,
isPrimary: true,
label : 'mobile',
}
const contact = {
[Contacts.Fields.FirstName]: item.name,
[Contacts.Fields.Company]: item.organization,
[Contacts.Fields.JobTitle]: item.position,
[Contacts.Fields.Note]: 'Some note',
[Contacts.Fields.Emails]: [emailDict],
[Contacts.Fields.PhoneNumbers]: [phoneDict],
};
try{
const contactId = await Contacts.addContactAsync(contact);
....
According to the API says about the types (string or booleans) is OK what I’m saving. Other thing, is Contacts.Fields.Emails and Contacts.Fields.PhoneNumbers are array.
Is working flawless in iOS.
In Android (after found out that I can’t write a contact with just WRITE_CONTACTS permissions, also READ_CONTACTS is needed to write) the contact is saved, but just the first name, company, job title and note. No email or PhoneNumber are saved. I tried without the [ ]
chars in Android (passing just the value of phone number and email) but is the same, does not works.
Thanks for your help!