ContactManager.RequestStoreAsync() throws System.UnauthorizedAccessException(ContactManager.RequestStoreAsync() 抛出 System.UnauthorizedAccessException)
问题描述
我正在尝试在 Windows 10 通用应用程序 API 中使用 ContactManager 类.我正在尝试在 Windows 10 桌面计算机上执行此操作.
I am trying to use the ContactManager class in the Windows 10 Universal apps API. I am trying to do this on a Windows 10 Desktop machine.
我在尝试使用 ContactManager.RequestStoreAsync() 请求联系人列表时收到异常System.UnauthorizedAccessException".
I am receiving an exception, "System.UnauthorizedAccessException" when trying to request a list of contacts using ContactManager.RequestStoreAsync().
在以前的版本中,此功能仅适用于 Windows Phone 设备.微软文档只是说它现在需要一个 Windows 10 设备系列,但我没有任何运气.
In previous versions, this function only worked on Windows Phone devices. The Microsoft documentation just says it requires a Windows 10 Device family now, but I'm not having any luck.
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;
}
推荐答案
好吧,我想我自己找到了答案.看起来如果您手动将联系人"功能添加到 Package.appxmanifest 文件中,它将解决问题.
Alright, I think I discovered the answer on my own. Looks like if you add the "contacts" capability to the Package.appxmanifest file manually, it will fix the issue.
此功能没有 UI 选项.您必须以某种方式知道它存在,在文本编辑器而不是 UI 中编辑文件,然后添加:
There is no UI option for this capability. You have to somehow know it exists, edit the file in a text editor instead of in the UI, and add:
<uap:Capability Name="contacts" />
这篇关于ContactManager.RequestStoreAsync() 抛出 System.UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ContactManager.RequestStoreAsync() 抛出 System.UnauthorizedAccessException
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
