In this article, the purpose of the code is to fetch contact details from an iOS device.
For OS version < 9.0 'ABAddressBook' is used for performing any operation related to contact. But after OS version 9.0 'CNContact' is used for the same.
So, here, we will fetch the contact information by using 'CNContact' which is used for the OS version >= 9.0
Here we go!
Basic Steps
Create a new project with the name 'Read-Contact'. On the File menu, click New Project.
Select 'Single View App (iPhone)' project and name it as 'Read-Contact'.
Under Installed > Visual C# > iOS > iPhone > Single View App (iPhone).
Step 1
We need to add the Permission Key in plist.info. Right-click on 'info.plist', and select 'Open with...' then select 'Automatic Editor Selector (XML)' and then paste the below 'key' and 'value' over there.
- <key>NSContactsUsageDescription</key>
- <string>This app requires contacts access to function properly.</string>
Step 2
We need to create a View Model class for contact. So, create a new class with the name 'ContactVm' and add the below properties in that class.
- public IList EmailId { get; set; }
- public IList PhoneNumbers { get; set; }
- public string GivenName { get; set; }
- public string FamilyName { get; set; }
- public bool IsSelected { get; set; }