Exemple #1
0
        void ShowUnknownPersonViewController()
        {
            using (var contact = new ABPerson()) {
                using (var email = new ABMutableStringMultiValue()) {
                    bool didAdd = email.Add("*****@*****.**", ABLabel.Other);

                    if (didAdd)
                    {
                        try {
                            contact.SetEmails(email);

                            var upvc = new ABUnknownPersonViewController {
                                DisplayedPerson           = contact,
                                AllowsAddingToAddressBook = true,
                                AllowsActions             = true,
                                AlternateName             = "John Appleseed",
                                Title   = "John Appleseed",
                                Message = "Company, Inc"
                            };
                            upvc.PersonCreated        += HandlePersonCreated;
                            upvc.PerformDefaultAction += HandlePerformDefaultAction;

                            NavigationController.PushViewController(upvc, true);
                        } catch (Exception) {
                            var alert = UIAlertController.Create("Error", "Could not create unknown user.", UIAlertControllerStyle.Alert);
                            alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, null));
                            PresentViewController(alert, true, null);
                        }
                    }
                }
            }
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        /*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);
        }
        async void ShowNewContactViewController()
        {
            using (var contact = new ABPerson()) {
                try {
                    contact.FirstName = viewModel.Place.Name;

                    if (viewModel.Place.HasImage)
                    {
                        var data = await ResourceLoader.DefaultLoader.GetImageData(viewModel.Place.Photos[0].ImageUrl);

                        contact.Image = UIImage.LoadFromData(NSData.FromArray(data)).AsJPEG();
                    }

                    using (var phone = new ABMutableStringMultiValue()) {
                        phone.Add(viewModel.Place.PhoneNumberFormatted, ABLabel.Other);
                        contact.SetPhones(phone);
                    }

                    using (var webSite = new ABMutableStringMultiValue()) {
                        webSite.Add(viewModel.Place.Website, ABLabel.Other);
                        contact.SetUrls(webSite);
                    }

                    var upvc = new ABUnknownPersonViewController {
                        DisplayedPerson           = contact,
                        AllowsAddingToAddressBook = true,
                        AllowsActions             = true,
                        AlternateName             = viewModel.Place.Name,
                        Title = viewModel.Place.Name
                    };

                    NavigationController.PushViewController(upvc, true);
                } catch (Exception) {
                    var alert = UIAlertController.Create("Error", "Could not create unknown user.", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            }
        }
Exemple #5
0
        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();
        }
		async void ShowNewContactViewController ()
		{
			using (var contact = new ABPerson ()) {
				try {

					contact.FirstName = viewModel.Place.Name;

					if (viewModel.Place.HasImage) {
						var data = await ResourceLoader.DefaultLoader.GetImageData(viewModel.Place.Photos[0].ImageUrl);
						contact.Image = UIImage.LoadFromData(NSData.FromArray(data)).AsJPEG();
					}

					using (var phone = new ABMutableStringMultiValue ()) {
						phone.Add(viewModel.Place.PhoneNumberFormatted, ABLabel.Other);
						contact.SetPhones(phone);
					}

					using (var webSite = new ABMutableStringMultiValue ()) {
						webSite.Add(viewModel.Place.Website, ABLabel.Other);
						contact.SetUrls(webSite);
					}

					var upvc = new ABUnknownPersonViewController {
						DisplayedPerson = contact,
						AllowsAddingToAddressBook = true,
						AllowsActions = true,
						AlternateName = viewModel.Place.Name,
						Title = viewModel.Place.Name
					};

					NavigationController.PushViewController(upvc, true);
				} catch (Exception) {
					var alert = UIAlertController.Create("Error", "Could not create unknown user.", UIAlertControllerStyle.Alert);
					alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, null));
					PresentViewController(alert, true, null);
				}
			}
		}
Exemple #7
0
        public void Save(Contact contact)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            CheckStatus();

            //convert the Contact to a ABPerson
            ABPerson person = new ABPerson();

            ABMutableDictionaryMultiValue addresses = new ABMutableDictionaryMultiValue();

            foreach (var item in contact.Addresses)
            {
                NSMutableDictionary a = new NSMutableDictionary();
                a.Add(new NSString(ABPersonAddressKey.City), NSStringNotNil(item.City));
                a.Add(new NSString(ABPersonAddressKey.State), NSStringNotNil(item.Region));
                a.Add(new NSString(ABPersonAddressKey.Zip), NSStringNotNil(item.PostalCode));
                a.Add(new NSString(ABPersonAddressKey.Street), NSStringNotNil(item.StreetAddress));
                addresses.Add(a, NSStringNotNil(item.Label));
            }
            person.SetAddresses(addresses);

            //Todo contact.DisplayName missing in ABPerson?
            //DisplayName = RelatedNames ???
            //ABMutableStringMultiValue relatedNames = new ABMutableStringMultiValue();
            //relatedNames.Add(ABPersonProperty.RelatedNames.ToString(), NSStringNotNil(contact.DisplayName));
            //person.SetRelatedNames(relatedNames);

            if (contact.Birthday.Year > 1)
            {
                person.Birthday = DateTime.SpecifyKind(contact.Birthday, DateTimeKind.Local);
            }

            ABMutableStringMultiValue emails = new ABMutableStringMultiValue();

            foreach (var item in contact.Emails)
            {
                emails.Add(item.Address, NSStringNotNil(item.Label));
            }
            person.SetEmails(emails);

            person.FirstName = contact.FirstName;

            //contact.InstantMessagingAccounts missing in ABPerson?

            person.LastName   = contact.LastName;
            person.MiddleName = contact.MiddleName;
            person.Nickname   = contact.Nickname;

            string notes = "";

            foreach (var item in contact.Notes)
            {
                notes += item.Contents + Environment.NewLine + Environment.NewLine;
            }
            person.Note = notes;

            //Todo multiple organizations are not supportet?
            if (contact.Organizations.Count() > 0)
            {
                person.Organization = contact.Organizations.FirstOrDefault().Name;
            }

            ABMutableStringMultiValue phones = new ABMutableStringMultiValue();

            foreach (var item in contact.Phones)
            {
                phones.Add(item.Number, NSStringNotNil(item.Label));
            }
            person.SetPhones(phones);

            person.Prefix = contact.Prefix;

            ABMutableStringMultiValue relationships = new ABMutableStringMultiValue();

            foreach (var item in contact.Relationships)
            {
                relationships.Add(item.Name, NSStringNotNil(item.Type.ToString()));
            }
            person.SetRelatedNames(relationships);

            person.Suffix = contact.Suffix;

            ABMutableStringMultiValue websites = new ABMutableStringMultiValue();

            foreach (var item in contact.Websites)
            {
                websites.Add(item.Address, NSStringNotNil("Url"));
            }
            person.SetUrls(websites);

            this.addressBook.Add(person);
            this.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();
        }
Exemple #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contactWebsiteList">
        /// A <see cref="System.String[]"/>
        /// </param>
        /// <returns>
        /// A <see cref="ABMultiValue<System.String>"/>
        /// </returns>
        private ABMultiValue<string> ConvertContactWebsitesToNative(string[] contactWebsiteList)
        {
            ABMutableStringMultiValue multableMultilabel = new ABMutableStringMultiValue();

            if(contactWebsiteList!=null) {
                foreach(string website in contactWebsiteList) {

                    NSString label = ABLabel.Other; // default is "Other"

                    multableMultilabel.Add(website, label);
                }
            }

            return multableMultilabel;
        }
Exemple #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contactPhoneList">
        /// A <see cref="ContactPhone[]"/>
        /// </param>
        /// <returns>
        /// A <see cref="ABMultiValue<System.String>"/>
        /// </returns>
        private ABMultiValue<string> ConvertContactPhonesToNative(ContactPhone[] contactPhoneList)
        {
            ABMutableStringMultiValue multableMultilabel = new ABMutableStringMultiValue();

            if(contactPhoneList!=null) {
                foreach(ContactPhone contactPhone in contactPhoneList) {

                    NSString label = ABLabel.Other; // default is "Other"
                    if(contactPhone.Type == NumberType.Other && contactPhone.IsPrimary) {
                        label = ABPersonPhoneLabel.Main;
                    } else if(contactPhone.Type == NumberType.Pager) {
                        label = ABPersonPhoneLabel.Pager;
                    } else if(contactPhone.Type == NumberType.Mobile) {
                        label = ABPersonPhoneLabel.Mobile;
                    } else if(contactPhone.Type == NumberType.WorkFax) {
                        label = ABPersonPhoneLabel.WorkFax;
                    } else if(contactPhone.Type == NumberType.HomeFax) {
                        label = ABPersonPhoneLabel.HomeFax;
                    } else if(contactPhone.Type == NumberType.Work) {
                        label = ABLabel.Work;
                    } else if(contactPhone.Type == NumberType.FixedLine) {
                        label = ABLabel.Home;
                    }

                    multableMultilabel.Add(contactPhone.Number, label);
                }
            }

            return multableMultilabel;
        }
Exemple #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contactEmailList">
        /// A <see cref="ContactEmail[]"/>
        /// </param>
        /// <returns>
        /// A <see cref="ABMultiValue<System.String>"/>
        /// </returns>
        private ABMultiValue<string> ConvertContactEmailsToNative(ContactEmail[] contactEmailList)
        {
            ABMutableStringMultiValue multableMultilabel = new ABMutableStringMultiValue();

            if(contactEmailList!=null) {
                foreach(ContactEmail contactEmail in contactEmailList) {

                    NSString label = ABLabel.Other; // default is "Other"
                    if(contactEmail.Type == DispositionType.HomeOffice) {
                        label = ABLabel.Home;
                    } else if(contactEmail.Type == DispositionType.Work) {
                        label = ABLabel.Work;
                    }

                    // Following data not provided on native API.
                    //<< contactEmail.CommonName
                    //<< contactEmail.Firstname
                    //<< contactEmail.IsPrimary
                    //<< contactEmail.Surname

                    multableMultilabel.Add(contactEmail.Address, label);
                }
            }

            return multableMultilabel;
        }
        public void ShowAddContactController(UINavigationController navigationController, User user)
        {
            ABNewPersonViewController abController = new ABNewPersonViewController ();

            ABPerson person = new ABPerson ();

            KeyValuePair <string, string> namePair = GetFirstAndLastName (user);

            person.FirstName = namePair.Key;
            person.LastName = namePair.Value;

            if (!string.IsNullOrEmpty (user.Company))
            {
                person.Organization = user.Company;
            }

            if (!string.IsNullOrEmpty (user.Phone))
            {
                ABMutableMultiValue<string> phones = new ABMutableStringMultiValue();
                phones.Add(user.Phone, ABPersonPhoneLabel.Main);
                person.SetPhones(phones);
            }

            if (!string.IsNullOrEmpty (user.Email))
            {
                ABMutableMultiValue<string> emails = new ABMutableStringMultiValue();
                emails.Add(user.Email, null);
                person.SetEmails(emails);
            }

            // Get any image from cache
            byte [] data = Engine.Instance.ImageCache.FindAny (user);

            if (data != null && data.Length > 0)
            {
                person.Image = NSData.FromArray(data);
            }

            abController.DisplayedPerson  = person;

            abController.NewPersonComplete += delegate {
                navigationController.PopViewControllerAnimated (true);
            };

            navigationController.PushViewController (abController, true);

            if (OnAddContactCompleted != null)
                OnAddContactCompleted ();
        }
		void ShowUnknownPersonViewController ()
		{
			using (var contact = new ABPerson ()) {
				using (var email = new ABMutableStringMultiValue ()) {
					bool didAdd = email.Add ("*****@*****.**", ABLabel.Other);

					if (didAdd) {
						try {
							contact.SetEmails (email);

							var upvc = new ABUnknownPersonViewController {
								DisplayedPerson = contact,
								AllowsAddingToAddressBook = true,
								AllowsActions = true,
								AlternateName = "John Appleseed",
								Title = "John Appleseed",
								Message = "Company, Inc"
							};
							upvc.PersonCreated += HandlePersonCreated;
							upvc.PerformDefaultAction += HandlePerformDefaultAction;

							NavigationController.PushViewController (upvc, true);
						} catch (Exception) {
							var alert = UIAlertController.Create ("Error", "Could not create unknown user.", UIAlertControllerStyle.Alert);
							alert.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Default, null));
							PresentViewController (alert, true, null);
						}
					}
				}
			}
		}