I want to read all Names from the AdressBook in the Smartphone. I've tested following code, but it won't work:
CrossContacts.Current.PreferContactAggregation = false;
var hasPermission = CrossContacts.Current.RequestPermission().Result;
if (hasPermission)
{
Contacts = CrossContacts.Current.Contacts.Select(
contact => contact.FirstName + " " + contact.LastName);
}
Also Visual Studio throws an exception like following:
System.ArgumentException: Expression of type 'Plugin.Contacts.ProjectionReader
1[System.String]' cannot be used for return type 'System.Linq.EnumerableQuery
1[System.String]'
What's the problem here?
If you want to return all the contacts with the first/last name concatenated together, return them to a List<string>
instead of a List<Contact>
:
List<string> nameList = CrossContacts.Current.Contacts.Select(contact => contact.FirstName + " " + contact.LastName).ToList();
If you are trying to return the whole Contact
record to a List:
List<Contact> contacts = CrossContacts.Current.Contacts.ToList();
Note: Be aware that with unified contacts, a user can have thousands of contacts that could be returned since you are applying no filtering.
我认为这是当前Xamarin插件中的错误: https : //github.com/jamesmontemagno/Xamarin.Plugins/issues/272
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.