Jon*_*Jon 2 c# windows windows-store-apps windows-10
我试图在Windows 10 Universal apps 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;
}
Run Code Online (Sandbox Code Playgroud)
好吧,我想我自己就找到了答案.看起来如果您手动将"联系人"功能添加到Package.appxmanifest文件,它将解决问题.
此功能没有UI选项.您必须以某种方式知道它存在,在文本编辑器中而不是在UI中编辑文件,并添加:
<uap:Capability Name="contacts" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1010 次 |
| 最近记录: |