private void CadastraContatos(List <Contato> contatos) { foreach (Contato contatoArquivo in contatos) { var novoContato = new ABPerson(); novoContato.FirstName = contatoArquivo.NomeFuncionario; novoContato.LastName = contatoArquivo.SobrenomeFuncionario; var fones = new ABMutableStringMultiValue(); var emails = new ABMutableStringMultiValue(); foreach (Telefone telefone in contatoArquivo.Telefones) { fones.Add(telefone.DDD + telefone.Numero, ABPersonPhoneLabel.Main); } novoContato.SetPhones(fones); foreach (String email in contatoArquivo.Emails) { emails.Add(email, ABPersonPhoneLabel.Main); } novoContato.SetEmails(emails); agenda.Add(novoContato); agenda.Save(); } }
/*public static async Task<bool> SendSMS(string number, string message, string name, * string ConfirmOrBOM, bool AutoCall = false, string TodayOrTomorrow = null) * { * //var notifier = new iOSReminderService(); * try * { * var vc = UIApplication.SharedApplication.KeyWindow.RootViewController; * * while (vc.PresentedViewController != null) * { * vc = vc.PresentedViewController; * } * if (MFMessageComposeViewController.CanSendText) * { * Console.WriteLine("SMS available"); * * var messageController = * new MessageComposeController(); * * messageController.Finished += * //async * (sender, e) => * { * Console.WriteLine("sms sent: {0}", messageController.Body); * AutoCaller.Calling = false; * if (string.Equals(ConfirmOrBOM, Values.BOM)) * { * CalendarService.IsConfirmingAppointments = false; * * //set notification time to confirm appointment * } * else { * CalendarService.IsConfirmingAppointments = true; * * } * messageController.DismissViewController(DeviceUtil.CanAnimate, null); * }; * * messageController.Body = message; * messageController.Recipients = new string[] { number }; * vc.PresentModalViewController(messageController, false); * } * else { * Console.WriteLine("Can't send text"); * } * return true; * } * catch (Exception e) * { * Console.WriteLine("PhoneContacts.SendSMS() error: {0}", e.Message); * if (string.Equals(ConfirmOrBOM, Values.BOM)) * { * //notifier.Remind(DateTime.Now.AddMilliseconds(0), "BOM Confirmation failed sending to " + name, "Text Confirmation Failed"); * } * else { * * if (string.Equals(TodayOrTomorrow, Values.TODAY)) * { * //notifier.Remind(DateTime.Now.AddMilliseconds(0), "SMS failed to send", "Couldn't confirm " + name + " for later's meeting"); * } * else { * //notifier.Remind(DateTime.Now.AddMilliseconds(0), "SMS failed to send", "Couldn't confirm " + name + " for tomorrow's meeting"); * } * } * } * return false; * }*/ /*string SaveDefaultImage(ContactData contact){ * string filename = System.IO.Path.Combine (Environment.GetFolderPath * (Environment.SpecialFolder.Personal), * "placeholder-contact-male.png"); * * Console.WriteLine("Assigned default image to {0} {1}. Saving it as {1}", * contact.FirstName, contact.LastName, filename); * * return filename; * } * string SaveImageThenGetPath(ContactData contact, NSData image, ABPersonImageFormat format){ * string filename = ""; * * try{ * if(format == ABPersonImageFormat.Thumbnail){ * filename = System.IO.Path.Combine (Environment.GetFolderPath * (Environment.SpecialFolder.Personal), * string.Format("{0}.jpg", contact.ID)); * }else{ * filename = System.IO.Path.Combine (Environment.GetFolderPath * (Environment.SpecialFolder.Personal), * string.Format("{0}-large.jpg", contact.ID)); * } * * image.Save (filename, true); * * Console.WriteLine("Found {0} {1}'s image. Saving it as {2}", * contact.FirstName, contact.LastName, filename); * * return filename; * }catch(Exception e){ * Console.WriteLine ("Error in SaveImageThenGetPath(): {0}", e.Message); * } * return string.Empty; * }*/ public bool SaveContactToDevice(string firstName, string lastName, string phone, string aff) { try { ABAddressBook ab = new ABAddressBook(); ABPerson p = new ABPerson(); p.FirstName = firstName; p.LastName = lastName; p.Organization = aff; //p.GetImage(ABPersonImageFormat.Thumbnail). ABMutableMultiValue <string> phones = new ABMutableStringMultiValue(); phones.Add(phone, ABPersonPhoneLabel.Mobile); p.SetPhones(phones); ab.Add(p); ab.Save(); UserDialogs.Instance.ShowSuccess("Contact saved: " + firstName + " " + lastName, 2000); return(true); } catch (Exception e) { System.Console.WriteLine("[iOS.PhoneContacts] Couldn't save contact: {0} {1}, {2}", firstName, lastName, e.Message); UserDialogs.Instance.ShowError("Failed to save contact: " + firstName + " " + lastName + ". Pls try again.", 2000); } return(false); }
private void PopulateContacts() { var addressBook = new ABAddressBook(); var people = addressBook.GetPeople(); // clear address book foreach (var person in people) { addressBook.Remove(person); } addressBook.Save(); var random = new Random(); // create 200 random contacts foreach (var name in _names) { // create an ABRecordRef var record = new ABPerson(); record.FirstName = name[0]; record.LastName = name[1]; var phones = new ABMutableStringMultiValue(); phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Mobile); if (random.Next() % 2 == 1) { phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Main); } record.SetPhones(phones); addressBook.Add(record); } addressBook.Save(); }
private void PopulateContacts() { var addressBook = new ABAddressBook(); var people = addressBook.GetPeople(); // clear address book foreach(var person in people) { addressBook.Remove(person); } addressBook.Save(); var random = new Random(); // create 200 random contacts foreach (var name in _names) { // create an ABRecordRef var record = new ABPerson(); record.FirstName = name[0]; record.LastName = name[1]; var phones = new ABMutableStringMultiValue(); phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Mobile); if(random.Next() % 2 == 1) { phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Main); } record.SetPhones(phones); addressBook.Add(record); } addressBook.Save(); }