Beispiel #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);
                        }
                    }
                }
            }
        }
        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);
                }
            }
        }
		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);
				}
			}
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "New and Unknown Contacts";

            // shows the create new contact screen when the button is clicked
            btnCreateNewContact.TouchUpInside += (s, e) => {
                // instantiate a new ABNewPersonViewController
                addressBookNewPerson = new ABNewPersonViewController();

                // create a person from the fields on the screen so we can prepopulate the
                // controller with data
                ABPerson person = new ABPerson();
                person.FirstName = txtFirstName.Text;
                person.LastName  = txtLastName.Text;

                // prepopulate the controller with the person
                addressBookNewPerson.DisplayedPerson = person;

                // push the controller onto the nav stack
                NavigationController.PushViewController(addressBookNewPerson, true);

                // wire up the new person complete handler to pop the controller off the stack
                addressBookNewPerson.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs args) => {
                    // if the "done" button was clicked, rather than cancel
                    if (args.Completed)
                    {
                        // show an alert view with the new contact ID
                        new UIAlertView("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show();
                    }

                    // pop the controller off the stack
                    // HACK: NavigationController.PopViewControllerAnimated to NavigationController.PopViewController
                    NavigationController.PopViewController(true);
                };
            };

            //
            btnPromptForUnknown.TouchUpInside += (s, e) => {
                // instantiate a new unknown person controller
                addressBookUnknownPerson = new ABUnknownPersonViewController();

                // create a person from the fields on the screen so we can prepopulate the
                // controller with data
                ABPerson person = new ABPerson();
                person.FirstName = txtFirstName.Text;
                person.LastName  = txtLastName.Text;

                // prepopulate the controller with the person
                addressBookUnknownPerson.DisplayedPerson = person;

                // allow adding to address book
                addressBookUnknownPerson.AllowsAddingToAddressBook = true;

                // allow them to share the contact, make calls, click on urls, etc in the controller
                addressBookUnknownPerson.AllowsActions = true;

                // push the controller onto the nav stack
                NavigationController.PushViewController(addressBookUnknownPerson, true);

                // handle the person created event
                addressBookUnknownPerson.PersonCreated += (object sender, ABUnknownPersonCreatedEventArgs args) => {
                    Console.WriteLine("PersonCreated event raised");

                    // this dialog can be cancelled out of as well, but there is no Completed property, so we
                    // just have to do a null check
                    if (args.Person != null)
                    {
                        // show an alert view with the new contact ID
                        new UIAlertView("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show();
                    }
                };

                // you can also handle the perform default action event to determine whether or not the action should be allowed
                // to be perfomed.
                //addressBookUnknownPerson.PerformDefaultAction += (object sender, ABPersonViewPerformDefaultActionEventArgs args) => {
                //	if(args.Property == ABPersonProperty.Url)
                //	{
                //		args.ShouldPerformDefaultAction = false;
                //	}
                //};
            };
        }
Beispiel #5
0
        /// <summary>
        /// Launchs the create new contact.
        /// </summary>
        /// <param name='contact'>
        /// Contact.
        /// </param>
        /// 
        protected void LaunchCreateNewContact(Contact contact)
        {
            ABPerson person = new ABPerson();
            // Basic Info
            person.FirstName = contact.Name;
            person.MiddleName = contact.Firstname;
            person.LastName = contact.Lastname;
            person.Nickname = contact.DisplayName;
            person.Note = contact.Notes;

            // Work info
            person.Organization = contact.Company;
            person.JobTitle = contact.JobTitle;
            person.Department =	contact.Department;

            // Addresses
            person.SetAddresses(this.ConvertContactAddressesToNative(contact.Addresses));

            // Phones
            person.SetPhones(this.ConvertContactPhonesToNative(contact.Phones));

            // Emails
            person.SetEmails(this.ConvertContactEmailsToNative(contact.Emails));

            // Websites
            person.SetUrls(this.ConvertContactWebsitesToNative(contact.WebSites));

            // Photo
            if(contact.Photo==null && contact.PhotoBase64Encoded!=null) {
                contact.Photo = Convert.FromBase64String(contact.PhotoBase64Encoded);
            }
            if(contact.Photo!=null) {
                NSData imageData = this.ConvertContactBinaryDataToNative(contact.Photo);
                if(imageData!=null && imageData.Length>0) {
                    person.Image = imageData;
                }
            }

            ABUnknownPersonViewController unknownPersonViewController = new ABUnknownPersonViewController();
            unknownPersonViewController.AddressBook = IPhoneServiceLocator.CurrentDelegate.AddressBook;
            unknownPersonViewController.AllowsActions = false;
            unknownPersonViewController.AllowsAddingToAddressBook = true;
            unknownPersonViewController.DisplayedPerson = person;
            unknownPersonViewController.PerformDefaultAction += HandlePerformDefaultAction;
            unknownPersonViewController.PersonCreated += HandleUnknownPersonCreated;
            unknownPersonViewController.Delegate = new UnknownPersonViewControllerDelegate();
            UIBarButtonItem backButtonItem = new UIBarButtonItem();
            backButtonItem.Title = "Cancel";
            backButtonItem.Clicked += HandleBackButtonItemClicked;
            unknownPersonViewController.NavigationItem.SetLeftBarButtonItem(backButtonItem,false);

            UINavigationController contactNavController = new UINavigationController();
            contactNavController.PushViewController(unknownPersonViewController,false);

            IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().PresentModalViewController (contactNavController, true);
            IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false);
        }
Beispiel #6
0
 public override bool ShouldPerformDefaultActionForPerson(ABUnknownPersonViewController personViewController, ABPerson person, int propertyId, int identifier)
 {
     UIApplication.SharedApplication.InvokeOnMainThread (delegate {
         SystemLogger.Log(SystemLogger.Module.PLATFORM, "On UnknownPersonViewControllerDelegate::ShouldPerformDefaultActionForPerson");
     });
     return true;
 }
Beispiel #7
0
 public override void DidResolveToPerson(ABUnknownPersonViewController personViewController, ABPerson person)
 {
     UIApplication.SharedApplication.InvokeOnMainThread (delegate {
         SystemLogger.Log(SystemLogger.Module.PLATFORM, "On UnknownPersonViewControllerDelegate::DidResolveToPerson");
         personViewController.DismissModalViewController(true);
         IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().DismissModalViewController(true);
     });
 }
		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);
						}
					}
				}
			}
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			Title = "New and Unknown Contacts";

			// shows the create new contact screen when the button is clicked
			btnCreateNewContact.TouchUpInside += (s, e) => {
				// instantiate a new ABNewPersonViewController
				addressBookNewPerson = new ABNewPersonViewController ();

				// create a person from the fields on the screen so we can prepopulate the
				// controller with data
				ABPerson person = new ABPerson ();
				person.FirstName = txtFirstName.Text;
				person.LastName = txtLastName.Text;

				// prepopulate the controller with the person
				addressBookNewPerson.DisplayedPerson = person;

				// push the controller onto the nav stack
				NavigationController.PushViewController (addressBookNewPerson, true);

				// wire up the new person complete handler to pop the controller off the stack
				addressBookNewPerson.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs args) => {

					// if the "done" button was clicked, rather than cancel
					if(args.Completed) {
						// show an alert view with the new contact ID
						new UIAlertView ("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show();
					}

					// pop the controller off the stack
					// HACK: NavigationController.PopViewControllerAnimated to NavigationController.PopViewController
					NavigationController.PopViewController(true);
				};
			};

			//
			btnPromptForUnknown.TouchUpInside += (s, e) => {
				// instantiate a new unknown person controller
				addressBookUnknownPerson = new ABUnknownPersonViewController ();

				// create a person from the fields on the screen so we can prepopulate the
				// controller with data
				ABPerson person = new ABPerson ();
				person.FirstName = txtFirstName.Text;
				person.LastName = txtLastName.Text;

				// prepopulate the controller with the person
				addressBookUnknownPerson.DisplayedPerson = person;

				// allow adding to address book
				addressBookUnknownPerson.AllowsAddingToAddressBook = true;

				// allow them to share the contact, make calls, click on urls, etc in the controller
				addressBookUnknownPerson.AllowsActions = true;

				// push the controller onto the nav stack
				NavigationController.PushViewController (addressBookUnknownPerson, true);

				// handle the person created event
				addressBookUnknownPerson.PersonCreated += (object sender, ABUnknownPersonCreatedEventArgs args) => {
					Console.WriteLine ("PersonCreated event raised");

					// this dialog can be cancelled out of as well, but there is no Completed property, so we
					// just have to do a null check
					if(args.Person != null) {
						// show an alert view with the new contact ID
						new UIAlertView ("Alert", "New contact created, ID: " + args.Person.Id.ToString (), null, "OK", null).Show ();
					}
				};

				// you can also handle the perform default action event to determine whether or not the action should be allowed
				// to be perfomed.
				//addressBookUnknownPerson.PerformDefaultAction += (object sender, ABPersonViewPerformDefaultActionEventArgs args) => {
				//	if(args.Property == ABPersonProperty.Url)
				//	{
				//		args.ShouldPerformDefaultAction = false;
				//	}
				//};
			};
		}