Essential Kit Tutorials
DocumentationDownload
Version 2
Version 2
  • Introduction
  • Features
  • Version 2 vs Version 1
  • Release Notes
    • ✅Version 2.7.4
    • Version 2.7.3
    • Version 2.7.2
    • Version 2.7.1
    • Version 2.7.0
    • Older Versions
      • Version 2.6.1
      • Version 2.6.0
      • Version 2.5.1
      • Version 2.5.0
      • Version 2.4.1
      • Version 2.4.0
      • Version 2.3.1
      • Version 2.3.0
      • Version 2.2.1
      • Version 2.2.0
      • Version 2.1.1
      • Version 2.1.0
      • Version 2.0.4
      • Version 2.0.3
      • Version 2.0.2
      • Version 2.0.1
      • Version 2.0.0
  • Plugin Overview
    • Settings
    • Folder Structure
    • Installation FAQ
    • Localisation
  • Address Book
    • Overview
    • Use Cases
    • Setup
    • Usage
    • Testing
    • FAQ
  • Billing Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
      • iOS
      • Android
    • FAQ
  • Cloud Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
    • FAQ
  • Deep Link Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • Testing
    • FAQ
  • Extras (Utilities)
    • Overview
    • Usage
  • Game Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • FAQ
  • Media Services
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Native UI
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Network Services
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Notification Services
    • Overview
    • Use Cases
    • Setup
      • iOS
      • Android
    • Usage
    • FAQ
  • Rate My App
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Sharing
    • Overview
    • Use Cases
    • Setup
    • Usage
      • Message Composer
      • Mail Composer
      • Social Share Composer
      • Share Sheet
    • FAQ
  • Web View
    • Overview
    • Use Cases
    • Setup
    • Usage
    • FAQ
  • Notes
    • Resolving Android Gradle Build Errors
    • Google Play Services Authentication
Powered by GitBook
On this page
  • Get Contacts Access Status
  • Request Contact Access
  • Read Contacts
  • Read Contacts with User Permission

Was this helpful?

Edit on GitHub
  1. Address Book

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.

using VoxelBusters.EssentialKit;

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.

AddressBookContactsAccessStatus status = AddressBook.GetContactsAccessStatus();

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.

AddressBook.RequestContactsAccess(callback: OnRequestContactsAccessFinish);
private void OnRequestContactsAccessFinish(AddressBookRequestContactsAccessResult result, Error error)
{
    Debug.Log("Request for contacts access finished.");
    Debug.Log("Address book contacts access status: " + result.AccessStatus);
}

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.

AddressBook.ReadContacts(OnReadContactsFinish);
private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
{
    if (error == null)
    {
        var     contacts    = result.Contacts;
        Debug.Log("Request to read contacts finished successfully.");
        Debug.Log("Total contacts fetched: " + contacts.Length);
        Debug.Log("Below are the contact details (capped to first 10 results only):");
        for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
        {
            Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
        }
    }
    else
    {
        Debug.Log("Request to read contacts failed with error. Error: " + error);
    }
}

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.

AddressBook.ReadContactsWithUserPermission(OnReadContactsFinish);
private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
{
    if (error == null)
    {
        var     contacts    = result.Contacts;
        Debug.Log("Request to read contacts finished successfully.");
        Debug.Log("Total contacts fetched: " + contacts.Length);
        Debug.Log("Below are the contact details (capped to first 10 results only):");
        for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
        {
            Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
        }
    }
    else
    {
        Debug.Log("Request to read contacts failed with error. Error: " + error);
    }
}
PreviousSetupNextTesting

Last updated 4 years ago

Was this helpful?