How to Open Addressbook New Contact Screen - addressbook

In my application I have UIBarButtonSystemItemAdd on right side of the navigation controller. On tapping of that plus icon I want to open address book in editable mode. Please refer the following image.
How to open address book UI for new contact in editable mode directly?

In the AddressBookUI.framework, there is a class called ABNewPersonViewController. Basically, what you want to do is this:
ABNewPersonViewController *abnpvc = [[ABNewPersonViewController alloc] init];
[abnpvc setNewPersonViewDelegate: self];
[self presentViewController: abnpvc animated: YES completion: nil];
This brings up the view you are looking for.

Related

Iphone ABUnknownPersonViewController using allowsAddingToAddressBook = YES issue

Let me explain what i want to do first. In native Iphone in the Recents tab if you click on a contact not found in any addressbook you have an option to "Add to Existing Contact"
After clicking on "Add to Existing Contact", a picker shows up and you make a selection. Afterwards it brings you to a ABPersonViewController automatically and allows you to edit or save the new contact:
I am trying to recreate this but having some issues. In my version, After I create the UnknownPersonViewController and the end user presses "Add to Existing Contact" a picker shows up and allows for selecting from the addressbook similar to native Iphone. But after making a selection the name gets automatically added to the addressbook and no personViewController appears to give the user a choice to add the contact or not. Even if i could just get it to not auto write to the addressbook after making a selection i could just have it show a personviewcontroller in edit mode right away.
So my issue is why is it automatically updating the addressbook after making a selection?
Im pushing the ABUnknownpersonviewcontroller onto a UITableviewController navigationcontroller. and im testing on a physical device with iOS 6.01
Here is some code:
ABRecordRef person = ABPersonCreate ();
ABMutableMultiValueRef multiValue = ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(multiValue, call.number, kABPersonPhoneMainLabel,
NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiValue, error);
if(multiValue) CFRelease(multiValue);
ABUnknownPersonViewController *unknownCtrl = [[ABUnknownPersonViewController alloc] init];
unknownCtrl.displayedPerson = person; //this has a phone number with "main" label
unknownCtrl.allowsActions = YES;
unknownCtrl.allowsAddingToAddressBook = YES;
unknownCtrl.editing=NO;
unknownCtrl.unknownPersonViewDelegate = self;
// unknownCtrl.addressBook=ABAddressBookCreate(); // I tried setting addressbook to nil and object
unknownCtrl.addressBook=nil;
[self setTitle:call.type forUIViewController:unknownCtrl];
[self.navigationController pushViewController:unknownCtrl animated:YES];
note: i have a similar problem to this post : http://forums.macrumors.com/archive/index.php/t-1023140.html
and perhaps https://discussions.apple.com/thread/1682620?start=0&tstart=0
UPDATE: it seems if i put the kABPersonPhoneMainLabel from the person, then it does not write the phone number to the contact. Aftewards what i did was in didResolveToPerson delegate i call the personviewcontroller in edit mode. This simulates the native behavior. This may answer my own question, thanks everyone.
ABUnknownPersonViewController doesn't expose many customization options, you need to implement your own version. It's not too hard though - the "Create New Contact" button just launches an ABNewPersonViewController, and the "Add to Existing Contact" launches an ABPeoplePickerNavigationController. Your ViewController should act as the delegates for those objects and controls what happens when they are completed.

ABPersonViewController drawn under the navgation bar

The context:
I am working on an app that maintains a list of contacts along with their record IDs for it's own reference.
When the user needs to change the number associated with a specific contact within the app, I am trying to display the ABPersonViewController so the user can choose the new number from the contact in AB.
The problem:
The problem is that the ABPersonViewController that is opened is starting all the way from the top of the screen as if it does not know that there is a navigation bar on the top.
As a result some of the top part of the ABPersonViewController screen (the top part of the person image and the top part of the name) is underneath the navigation bar.
Ideally i want it to look like this, but not in edit mode: http://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Art/person_view.jpg
Also I wanted to add a "cancel" button to the top right part of the nav bar. Trying to add that as a bar button is not working either.
The code:
this is how I am adding the ABPersonViewController to the navigationController:
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.personViewDelegate = self;
personViewController.displayedPerson = person;
[self.m_circleNavController pushViewController:personViewController animated:YES];
[personViewController release];
The self here is a UIVIewController.
The m_circleNavController is the UINavigationController to which the UIVIewController belongs.
I tried these 2 ways of showing the person view, but both behave the same way.
[self.m_circleNavController pushViewController:personViewController animated:YES];
[self.navigationController pushViewController:personViewController animated:YES];
I'm not too sure what I am doing wrong, or what is the best way to do it.
I tried a lot of different ways to display it in vain.
The viewcontroller was behaving as though it was starting about 40 pixels above the top edge of the screen.
I was able to fix it in a very weird way finally. In the init function of the viewcontroller I added the following line:
self.view.bounds = CGRectMake(0, -43, 320, 440);
But still no clue as to why it happens this way. I was to close to the deadline to look for a decent solution.
Hello I've been having the same problem as of the new iOS. When this happens on my custom view controllers I have been able to correct it with:
if (self.interfaceOrientation != UIInterfaceOrientationPortrait) { // UI is in landscape position
[self.tableView setContentInset:UIEdgeInsetsMake(32,0,0,0)];
} else { // UI is in portrait position
[self.tableView setContentInset:UIEdgeInsetsMake(44,0,0,0)];
}
But when using the ABPersonViewController I don't quite know how to handle this problem.
Hope someone has an idea...

Previous View after dismissModalViewControllerAnimated of email function somehow defect

i am trying and trying.... but no result yet.
i have a view with a navigationcontroller and -bar. in addition there is a tableview.
if you click on a row, the iphone email function is getting startet by using the email example from apple (MailComposerViewController.h and .m).
it opens and i am able to send or cancel the mail. after that the "dismissModalViewControllerAnimated" methode is dismissing the emailing view. everything looks right, i am in the previous view now, BUT:
when i want to use buttons from the navigationitem or if i want to add rows to the tableview, the app is crashing without any error message.
do i have to set something back or to "remove" something which is still there because of the mailing view?
it's really strange and i am searching now for hours....... :-(
thank you very much in advance!
hopefully someone has an idea.
EDIT:
ok, here i have the code now:
in a tableview which is included in a navcontroller i have following lines to open first a Subclass of UIViewController:
- (IBAction)Action:(id)sender
{
DetailViewController *editViewController = [[DetailViewController alloc] initWithNibName:#"TripDetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:editViewController animated:YES];
editViewController.navigationItem.prompt = #"Details";
[editViewController release];
}
in the DetailViewController following action is processed when the user clicks on the button:
- (IBAction)mailTrip:(id)sender {
MailComposerViewController *mailComposer = [[MailComposerViewController alloc] init];
[[[self view] window] addSubview:[mailComposer view]];
[mailComposer showPicker:sender];
}
when i press the related button, the MailComposerViewController pushes up correctly. all functions of the MailComposerViewController are working correct.
but when i send or cancel the mail and the MailComposerViewController disappears, my previous view doesn't work anymore.
in the MailComposerViewController-Example from apple the MailComposerViewController just disappear and the previous view is working fine again.... :-(
ok, i found the stupid simple problem.
the MailComposer-View was after dismissing it still over the previous view.
i did set the propert hidden after dismissing and now it works...
[self dismissModalViewControllerAnimated:YES];
[[self view] setHidden:YES];
but i am really not sure if this is the right way to do it...

iOS4 ABNewPersonViewController Loses Data Entered when attempting to add a Photo iPhone 4

I have implemented a basic add contact feature to an iOS 4 application. Following the documentation from Apple, I have created a navigation controller, and set its root view to the ABNewPersonViewController. I have implemented the delegate as well. The basic mechanics all work.
The problem I am having is when you add a photo to the new person that is very large (taking a photo or picking one from the library), the ABNewPersonViewController form returns empty when the camera controls are dismissed. No photo is in the add photo box either. If I pick a small image (say a screenshot from the iPhone), everything works. I can see from the debug output: Received memory warning. Level=1
Has anyone else run into this? Is there a way to set the photo quality to a lower setting for the ABNewPersonViewController? Any help appreciated.
ABNewPersonViewController *abNewPersonView = [[ABNewPersonViewController alloc] init];
abNewPersonView.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [UINavigationController alloc];
[newNavigationController initWithRootViewController:abNewPersonView];
[self presentModalViewController:newNavigationController animated:YES];
[abNewPersonView release];
[newNavigationController release];
If ABNewPersonViewController does not handle memory warnings correctly, file a bug with apple.

MFMailComposeViewController address book picker customization

Is it possible to customise the behavior of how the ABPeoplePickerNavigationController is displayed modally from the MFMailComposeViewController whenever a user presses the '+' icon in the 'To:' and 'Cc/Bcc:' fields?
I want to wrap the ABPeoplePickerNavigationController inside of another view controller before it is being presented modally. How do I do this?
What kind of functionality are you looking to add by wrapping the PeoplePicker in another view controller?
You can display the PeoplePicker with the following code:
ABPeoplePickerNavigationController *ab = [[ABPeoplePickerNavigationController alloc] init];
[ab setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
[ab setPeoplePickerDelegate:self];
[self presentModalViewController:ab animated:YES];
You may need to subclass ABPeoplePickerNavigationController depending on what you need to do.