【发布时间】:2015-10-22 07:42:20
【问题描述】:
我正在尝试在 Windows 10 通用应用程序 API 中使用 ContactManager 类。我正在尝试在 Windows 10 桌面计算机上执行此操作。
我在尝试使用 ContactManager.RequestStoreAsync() 请求联系人列表时收到异常“System.UnauthorizedAccessException”。
在以前的版本中,此功能仅适用于 Windows Phone 设备。微软文档只是说它现在需要一个 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;
}
【问题讨论】:
标签: c# windows windows-store-apps windows-10