Native Contacts
Welcome to the user guide for accessing native contacts on your device using JavaScript. This guide will walk you through the steps required to retrieve contact information using plain JavaScript (ES5) and ES6+ syntax.
1. Overview
Native contacts access allows you to fetch contact information stored on your device. This can be useful for various purposes such as filling forms, displaying auto-suggestions, or integrating contacts into your application.
2. Getting Started
Before accessing native contacts, make sure you have the necessary permissions to do so. This usually involves requesting permission from the user.
3. Plain JavaScript (ES5) Approach
3.1. Retrieve Permission Status
const { contacts } = window.WTN;
contacts.getPermissionStatus({
callback: function(data){
//data.status contains permission status
}
});
3.2. Retrieve All Contacts
contacts.getAll({
callback: function(data){
//data.contacts contains all contacts
}
});
4. ES6+ Module Import
4.1. Import Functions
import { getPermissionStatus, getAll } from "webtonative/NativeContacts";
getPermissionStatus({
callback: function(data){
//data.status contains permission status
}
});
getAll({
callback: function(data){
//data.contacts contains all contacts
}
});
5. Permission Status
The possible permission status values are:
authorized
: Permission has been granted.denied
: Permission has been denied.restricted
: Access has been administratively prohibited.notDetermined
: User has not yet been asked for permission.
6. Contact Data Structure
The contact data returned includes the following fields:
givenName
familyName
middleName
birthday
namePrefix
previousFamilyName
nameSuffix
nickname
organizationName
departmentName
jobTitle
phoneNumbers
(Array of Objects)label
phoneNumber
emailAddresses
(Array of Objects)label
emailAddress
postalAddresses
(Array of Objects)label
street
subLocality
city
subAdministrativeArea
state
postalCode
country
isoCountryCode
7. Conclusion
You now have the necessary information to retrieve native contacts on your device using JavaScript. Make sure to handle permissions correctly and utilize the returned data as per your application's requirements.