Jesse Liberty
Jesse Liberty

Reputation: 1414

Using Contacts in .NET MAUI

the .NET MAUI documentation (https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/communication/contacts?tabs=android) shows this:

var contact = await Microsoft.Maui.ApplicationModel.Communication.Contacts.PickContactAsync();

however, when I use it, contact always comes back null. Has something changed or am I missing something?

Upvotes: 0

Views: 1200

Answers (1)

Alexandar May - MSFT
Alexandar May - MSFT

Reputation: 10148

Firstly, make sure there are contacts in your device or emulator. When calling the method Microsoft.Maui.ApplicationModel.Communication.Contacts.PickContactAsync();, it'll require you to choose the existing contact, otherwise, it'll return NULL.

For Android, it can be simplified as code below:

var contact = await Contacts.Default.PickContactAsync();

For iOS and Windows, you can use the code below:

var contact = await Microsoft.Maui.ApplicationModel.Communication.Contacts.PickContactAsync();

Upvotes: 1

Related Questions