修改联系人时,ContactStore ContactChanged事件未触发

问题描述 投票:0回答:1

修改联系人或添加电话号码时,永远不会调用修改过的案例

 _contactStore.ContactChanged += _contactStore_ContactChanged;


private void _contactStore_ContactChanged(ContactStore sender, ContactChangedEventArgs args)
        {
            var defferal = args.GetDeferral();

            ContactChangeReader reader = sender.ChangeTracker.GetChangeReader();
            IReadOnlyList<ContactChange> changes = reader.ReadBatchAsync().AsTask().Result;

            while (changes.Count != 0)
            {
                foreach (ContactChange change in changes)
                {
                    switch (change.ChangeType)
                    {
                        case ContactChangeType.Modified: SomeLogic();
                          break;
                    }
                }
               changes = reader.ReadBatchAsync().AsTask().Result;
            }
            reader.AcceptChanges();
c# .net uwp windows-10-universal
1个回答
0
投票

问题可能是ContactStoreAccessType类型不正确。请尝试使用AllContactsReadWrite枚举类型。

ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite);
store.ContactChanged += Store_ContactChanged;

private void Store_ContactChanged(ContactStore sender, ContactChangedEventArgs args)
{

}
© www.soinside.com 2019 - 2024. All rights reserved.