为了获得所有联系人,我使用此代码:
var contactStore = await ContactManager.RequestStoreAsync();
var contacts = await contactStore.FindContactsAsync();
它运行良好,但是当我向我的应用程序联系人存储添加新联系人时,FindContactsAsync方法崩溃并返回“值不在预期范围内”异常。为了添加应用联系人,我使用以下代码:
var store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite,
ContactStoreApplicationAccessMode.ReadOnly);
var contact = new StoredContact(store) { DisplayName = "Test Contact" };
var props = await contact.GetPropertiesAsync();
props.Add(KnownContactProperties.MobileTelephone, "1234567");
await contact.SaveAsync();