Usage
Address Book allows access to contacts on mobile devices.
This feature allows you to read the contacts saved on the mobile devices. All Address Book features can be accessible from AddressBook static class.
Before using any of the plugin's features, you need to import the namespace.
1
using VoxelBusters.EssentialKit;
Copied!
After importing the namespace, AddressBook class is available for accessing all of the Address Book's features.

Get Contacts Access Status

Get the contacts access status to see if it's allowed to access or denied by the user. GetContactAccessStatus method returns AddressBookContactsAccessStatus to identify if the status is NotDetermined/Restricted/Denied/Authorized.
1
AddressBookContactsAccessStatus status = AddressBook.GetContactsAccessStatus();
Copied!

Request Contact Access

Request the permission if the contact access is not determined yet. Calling RequestContactsAccess might show up a permission dialog on the mobile devices allowing the user to take an action.
You need to pass a callback method to get the status of the user action.
1
AddressBook.RequestContactsAccess(callback: OnRequestContactsAccessFinish);
Copied!
1
private void OnRequestContactsAccessFinish(AddressBookRequestContactsAccessResult result, Error error)
2
{
3
Debug.Log("Request for contacts access finished.");
4
Debug.Log("Address book contacts access status: " + result.AccessStatus);
5
}
Copied!

Read Contacts

Fetch the contacts available for the user by calling ReadContacts method. You need to pass a callback to get the list of IAddressBookContact instances.
1
AddressBook.ReadContacts(OnReadContactsFinish);
Copied!
1
private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
2
{
3
if (error == null)
4
{
5
var contacts = result.Contacts;
6
Debug.Log("Request to read contacts finished successfully.");
7
Debug.Log("Total contacts fetched: " + contacts.Length);
8
Debug.Log("Below are the contact details (capped to first 10 results only):");
9
for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
10
{
11
Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
12
}
13
}
14
else
15
{
16
Debug.Log("Request to read contacts failed with error. Error: " + error);
17
}
18
}
Copied!

Read Contacts with User Permission

If you don't need much control on the permission access status but just want to go ahead with reading the contacts, you can call ReadContactsWithUserPermission. This call requests the permission internally and returns the contacts details if authorized or an error if user deny the permission.
1
AddressBook.ReadContactsWithUserPermission(OnReadContactsFinish);
Copied!
1
private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
2
{
3
if (error == null)
4
{
5
var contacts = result.Contacts;
6
Debug.Log("Request to read contacts finished successfully.");
7
Debug.Log("Total contacts fetched: " + contacts.Length);
8
Debug.Log("Below are the contact details (capped to first 10 results only):");
9
for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
10
{
11
Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
12
}
13
}
14
else
15
{
16
Debug.Log("Request to read contacts failed with error. Error: " + error);
17
}
18
}
Copied!
Last modified 10mo ago