How to auto sync Contact with UWP app?

131 Views Asked by At

I'm using ContactPicker to pick some contacts and save in my app via SQLite. 1. How to sync with my app when have change Name or Phone Number in People app of phone? 2. Or you have a best way to pick contacts, save and auto sync with app, please suggest me!

1

There are 1 best solutions below

0
On BEST ANSWER

If you want to access the contacts on the windows 10 device you can use the following code:

            var contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
        var contactLists = await contactStore.FindContactListsAsync();
        foreach (var cl in contactLists)
        {
            var cReader = cl.GetContactReader();
            var cBatch = await cReader.ReadBatchAsync();
            foreach (Contact c in cBatch.Contacts)
            {
                //Make a change
                c.Notes = c.Notes + c.DisplayName;
                await cl.SaveAsync();
            }
        }

This will however only allow to access the contacts that are owned by the app. You can change ContactStoreAccessType.AppContactsReadWrite to ContactStoreAccessType.AllContactsReadWrite, but this required special deployment by Microsoft as described here: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.contacts.contactstoreaccesstype.aspx.

I you use Office 365 your contacts can also accessed and changed to outlook online. Is this case it would much more sense to sync to office 365 using the graph.microsoft.com API (see http://graph.microsoft.io). Changes will that automatically be synced to you device.