Reading Contacts in Xamarin Forms
In this article, I’ll present to you how to read contacts from Portable Layer in Xamarin Forms. I’ve already created codes and you’ll use only one line code like this:
Just create a new project and add Xamarin.Forms.Contacts NuGet package to all Layers
We’ll use MainPage which comes from new project as default. Firsly add a listview to MainPage.XAML and go MainPage.Cs and add reading code which I read at top of article and bind it
Most important part is Permissions. Don’t forget to set permissions for each platform.
For Android, you can add permission to AndroidManifes.xml manually but my suggestion is, right click the Android project and click Properties than go Android Manifest tab, you’ll see permissions windows that allows you set permissons via checkboxes. Just check READ_CONTACTS permission.
For iOS, Right click the Info.plist and choose Open With opiton. Select XML Editor from there and add NSContactsUsageDescription as key and add a description between string tags why you want this permisson below the key into dict tags. (Sample is below.)
- Over Android 5.0 versions you need to request Runtime Permissons to reach contact data.
- Users won’t give permission for contacts. You can use Permission Plugin to avoid unexpected situations.