我正在尝试使用Windows 10通用应用程序API中的ContactManager类。 我正在尝试在Windows 10桌面计算机上执行此操作。
尝试使用ContactManager.RequestStoreAsync()请求联系人列表时,我收到exception“System.UnauthorizedAccessException”。
在以前的版本中,此function仅适用于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; }
好吧,我想我自己发现了答案。 看起来像是手动添加“联系人”功能到Package.appxmanifest文件,它将解决问题。
这个功能没有UI选项。 您必须以某种方式知道它存在,请在文本编辑器中而不是在UI中编辑该文件,然后添加:
<uap:Capability Name="contacts" />