private async Task CreateContactBindingsAsync() { ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync(); // Simulate call to web service List <ServerApi.ContactBinding> bindings = ServerApi.GetContactsFromWebServiceAsync(); foreach (ServerApi.ContactBinding binding in bindings) { ContactBinding myBinding = bindingManager.CreateContactBinding(binding.RemoteId); // This information is not displayed on the Contact Page in the People Hub app, but // is used to automatically link the contact binding with existent phone contacts. // Add as much information as possible for the ContactBinding to increase the // chances to find a matching Contact on the phone. myBinding.FirstName = binding.GivenName; myBinding.LastName = binding.FamilyName; myBinding.EmailAddress1 = binding.Email; myBinding.Name = binding.CodeName; // Don't crash if one binding fails, log the error and continue saving try { await bindingManager.SaveContactBindingAsync(myBinding); } catch (Exception e) { Logger.Log("MainPage", "Binding (" + binding.RemoteId + ") failed to save. " + e.Message); } } }
public async void CreateContactBindingsAsync() { ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync(); // Simulate call to web service TraktProfile[] profiles = await userDao.getUserFriends(); ContactStore store = await ContactStore.CreateOrOpenAsync(); foreach (TraktProfile profile in profiles) { ContactBinding myBinding = bindingManager.CreateContactBinding(profile.Username); if (!String.IsNullOrEmpty(profile.Name)) { if (profile.Name.Contains(" ")) { Regex regex = new Regex(@"\s"); String[] nameSplit = regex.Split(profile.Name); myBinding.FirstName = nameSplit[0]; myBinding.LastName = nameSplit[1]; } else { myBinding.LastName = profile.Name; } } try { if (!String.IsNullOrEmpty(profile.Name) && profile.Name.Contains(" ")) { Regex regex = new Regex(@"\s"); String[] nameSplit = regex.Split(profile.Name); AddContact(profile.Username, nameSplit[0], nameSplit[1], profile.Username, profile.Avatar, profile.Url); } else { AddContact(profile.Username, "", "", profile.Username, profile.Avatar, profile.Url); } await bindingManager.SaveContactBindingAsync(myBinding); } catch (Exception e) { Console.Write(e.InnerException); } } }