ContactManager.RequestStoreAsync () создает исключение System.UnauthorizedAccessException
Я пытаюсь использовать класс ContactManager в API универсальных приложений Windows 10. Я пытаюсь сделать это на компьютере с Windows 10 Desktop.
Я получаю исключение "System.UnauthorizedAccessException" при попытке запросить список контактов с помощью ContactManager.RequestStoreAsync ().
В предыдущих версиях эта функция работала только на устройствах Windows Phone. Документация Microsoft просто говорит, что сейчас требуется семейство устройств Windows 10, но мне не повезло.
using Windows.ApplicationModel.Contacts;
public async Task<List<String>> getContacts()
{
List<String> listResults = new List<string>();
ContactStore store = null;
IReadOnlyList<ContactList> list = null;
ContactReader reader = null;
ContactBatch batch = null;
// *** This RequestStoreAsync() call is where the exception is thrown. All the cases below have the same issue. ***
//store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite);
//store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
store = await ContactManager.RequestStoreAsync();
list = await store.FindContactListsAsync();
foreach (ContactList contactList in list)
{
reader = contactList.GetContactReader();
batch = await reader.ReadBatchAsync();
foreach (Contact contact in batch.Contacts)
{
listResults.Add(contact.Name);
}
}
return listResults;
}