RedCorners.Components.DeviceContacts 5.2.0

Access device contacts on iOS and Android.

Install-Package RedCorners.Components.DeviceContacts -Version 5.2.0
dotnet add package RedCorners.Components.DeviceContacts --version 5.2.0
<PackageReference Include="RedCorners.Components.DeviceContacts" Version="5.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RedCorners.Components.DeviceContacts --version 5.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NuGet: https://www.nuget.org/packages/RedCorners.Components.DeviceContacts

GitHub: https://github.com/saeedafshari/RedCorners.Components.DeviceContacts

Setting Up / Permissions

iOS

iOS info.plist:
<key>NSContactsUsageDescription</key>
<string>This app requires access to contacts.</string>

Android

Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
  <application ...>...</application>
  <uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>
MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
  ...
  global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
  DeviceContacts.Init(this);
  LoadApplication(new App());
  ...
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
  DeviceContacts.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  ...
  base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Listing Contacts

var provider = new DeviceContacts();
var contacts = await contacts.GetAllAsync();

It's strongly advised that you check for exceptions there, because GetAllAsync throws exceptions if the permission to read contacts is not granted:

try
{
  var provider = new DeviceContacts();
  var contacts = await contacts.GetAllAsync();
}
catch (Exception ex)
{
  App.Instance.DisplayAlert("Error", ex.ToString(), "OK");
}

Asking for permissions

When you call await contacts.GetAllAsync(), the library automatically displays the permission request dialog.

NuGet: https://www.nuget.org/packages/RedCorners.Components.DeviceContacts

GitHub: https://github.com/saeedafshari/RedCorners.Components.DeviceContacts

Setting Up / Permissions

iOS

iOS info.plist:
<key>NSContactsUsageDescription</key>
<string>This app requires access to contacts.</string>

Android

Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
  <application ...>...</application>
  <uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>
MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
  ...
  global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
  DeviceContacts.Init(this);
  LoadApplication(new App());
  ...
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
  DeviceContacts.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  ...
  base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Listing Contacts

var provider = new DeviceContacts();
var contacts = await contacts.GetAllAsync();

It's strongly advised that you check for exceptions there, because GetAllAsync throws exceptions if the permission to read contacts is not granted:

try
{
  var provider = new DeviceContacts();
  var contacts = await contacts.GetAllAsync();
}
catch (Exception ex)
{
  App.Instance.DisplayAlert("Error", ex.ToString(), "OK");
}

Asking for permissions

When you call await contacts.GetAllAsync(), the library automatically displays the permission request dialog.

Release Notes

Access device contacts on iOS and Android.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
5.2.0 47 7/7/2019
4.11.0 47 6/22/2019