how to hide some properties using ABPeoplePicker - iphone

When using peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person, a view with all of the contact's information is shown. I've seen apps which only display selected info only (e.g. phone numbers).
How can I do this? I only want to display the contact's name and phone numbers.
Thank you very much!

It's pretty simple. I customized ABPeoplePickerNavigationController to only show email addresses.
The code looks like this:
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
[peoplePicker setPeoplePickerDelegate:self];
[peoplePicker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
You can find a list of the available properties here.

I'm not sure if you can,
You could do this to get a list of people for the address book:
// get the default address book.
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
and then create your own custom picker view, showing only the information you want.

In Swift, you simply do this.
var people = ABPeoplePickerNavigationController()
people.peoplePickerDelegate = self
// 3 is for Phone Number
people.displayedProperties = [3]

Related

Should I use ABPersonViewController or ABUnknownPersonViewController

I am showing the details of a person using ABPersonViewController. Now I have a case, where I have to show the record(details) of a person, who is not in my addressbook. I have the properties(Name/Phone number/email/address) of this person. I don't want to save this person contact in my addressbook. But I need to show the person details(display all person properties). Should I use ABPersonViewController or ABUnknownPersonViewController in this case.
ABUnknownPersonViewController is used to represent a partial person and has the option to disallow adding the contact to the address book.
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.allowsAddingToAddressBook = NO;
unknownPersonViewController.displayedPerson = person; //person is an ABRecordRef

Popover tableview with dynamic array data

I am trying to reuse the popover tableview code such that when the user touches the Canada button, the provinces of Canada (Alberta, British Columbia, ...) are displayed; when the user touches the USA button the states of USA (Alabama, Alaska, ...) are displayed. The problem is when I hit the USA button after the Canada button, the first 12 states of the USA are not displayed by the 13 provinces/territories of Canada are still displayed.
I am following the code here
http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial
but modifying the setColorButtonTapped code to take an array so I can reuse the code for different arrays
- (IBAction)setColorButtonTapped:(id)sender withData:(NSArray *) data {
if (_colorPicker == nil) {
self.colorPicker = [[[ColorPickerController alloc]
initWithStyle:UITableViewStylePlain] autorelease];
_colorPicker.delegate = self;
self.colorPickerPopover = [[[UIPopoverController alloc]
initWithContentViewController:_colorPicker] autorelease];
}
[self.colorPickerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
_colorPicker.tableList = [data copy];
// I defined a property NSMutableArray *tableList
// I think the problem is with the way I copy the data }
Sorry about the fomatting of the code.
Thanks for your help in advance.
Joe
Joe, I'm guessing many will tell you to be a bit more specific. Nonetheless, one thing that caught my eye is that you don't seem to empty your .tableList anywhere on this code snippet.
Basically, try checking whether it has data or not before you copy new one into it. If it does, remove the old data and copy the new one.

Why doesn’t ABPersonViewController show any properties besides the name?

For some reason, ABPersonViewController is unwilling to display any properties aside from the name, no matter what properties are set for it to display.
I’m unable to use the AddressBookUI controllers to let a user select a contact to display, since my UI has custom requirements, otherwise I’d go that route (as Apple does in their sample project.)
Here’s the code that doesn’t work — am I missing something?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// ABContact is of my own creation
ABContact *contact = [self contactAtIndexPath: indexPath];
ABPersonViewController *viewController = [[ABPersonViewController alloc] init];
// This returns a valid ABRecordRef, as indicated by the fact that the
// controller does display the name of this contact when it is loaded
viewController.displayedPerson = contact.record;
// Copied directly from Apple’s QuickContacts sample project
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
viewController.displayedProperties = displayedItems;
[self.navigationController pushViewController: viewController animated: YES];
[viewController release];
}
ABContact is from Erica Sadun's ObjC wrapper (ABContactsHelper), right?
I'm using it too and found that for some reason, Apple's ABPersonViewController somehow treats supplied ABRecordRef as contact.record differently than if you directly use C functions.
Thus this:
ABContact *person = ...;
ABPersonViewController *personVC = ...;
personVC.displayedPerson = person.record;
will load almost nothing into the controller. Sometimes first/last name, sometimes not even that. However, if you do this:
ABContact *person = ...;
ABPersonViewController *personVC = ...;
ABAddressBookRef addressBook = ABAddressBookCreate();
personVC.displayedPerson = ABAddressBookGetPersonWithRecordID(addressBook, person.recordID);
then it will load everything.
Previous answer says that ABAddressBookCreate is required for the constants to have a value, but this is already done in [ABContactsHelper addressBook] call (first thing I call in my code). This it's really puzzling where it gets lost. But the previous does work, consistently.
The key is not to release the ABAddressBookRef before displaying the view controller. I create a static instance in an +initialize method and keep it around.
The value of these constants is undefined until one of the following functions has been called: ABAddressBookCreate, ABPersonCreate, ABGroupCreate.
The above is come from apple document. I think those property constants are not valid for above reason.
This list of properties only affects displaying "properties choosing dialog" (after person has been choosen). Person contact's properties like first, middle, last names, company, etc. are always the same (in both dialogs). If you include kABPersonFirstNameProperty, kABPersonMiddleNameProperty, etc. keys in the list they are ignored, only kABPersonPhoneProperty, kABPersonEmailProperty, etc. have effect.

Problem with pushviewcontroller animation while fetching iPhone contact's image

I am trying to show a contact from the iPhone address book. I fetch the names and image of the contacts. Then I pass these details to Detail view.
Now the problem is when I push the detail view, the animation is very slow and choppy. This happens only when I fetch the contact detail which has image. The pushviewcontroller animation works perfectly fine when the contact detail does not contain image.
Also I noticed that this problem occurs only in iPhone 4.0. When I tested this on iPhone 3gs, it worked perfectly. So I am thinking this might be device specific problem.
I fetch the contact name in the following way:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef record=ABCFindPersonMatchingPhoneNumber(addressBook,
number, 0, 0);
if(record)
{
NSString *name=(NSString *)ABRecordCopyCompositeName(record);
NSLog(#"Contact Name %#",name);
}
And I fetch the contact image in the following way:
if (record && ABPersonHasImageData(record))
{
CFDataRef data;
data = ABPersonCopyImageData(record);
if (data)
{
NSLog(#"ImageFound");
imageData=[[NSData alloc] initWithData:(NSData *)data];
}
}
Then I pass the imageData to the Detail View
DetailView *detail=[[DetailView alloc] initWithNibName:#"DetailView" bundle:nil];
detail.imageData=imageData
[self.navigationController pushViewController:detail animated:YES];
How can I improve on this?
I know this is an old thread, but just in case if someone comes to this here with a related problem:
add
[detail view];
right after the initialization and before setting any #properties (detail.imageData=imageData;) - because the outlets of the segue are not set yet.

Insert picture image to the ABUnknownPersonViewController view in iPhone application contact page

I am working on 'About" section of my iPhone application.
I want to show some of the contributors details as a standard ABUnknownPersonViewController view.
I am creating person view using simple 'school' code:
ABRecordRef aContact = ABPersonCreate();
ABMultiValueAddValueAndLabel(email, #"John-Appleseed#mac.com", kABOtherLabel, NULL);
ABRecordSetValue(aContact, kABPersonEmailProperty, email, &anError);
ABUnknownPersonViewController *picker =[[ABUnknownPersonViewController alloc] init];
picker.displayedPerson = aContact;
picker.alternateName = person.fullName;
picker.title = [NSString stringWithFormat:#"About %#", person.firstName];
picker.message = person.message;
... and so on ....
However - I haven't found any solution how to insert person picture to the ABUnknownPersonViewController image/picture field using <AddressBook/AddressBook.h>.
Anybody knows if it is possible? I have no luck to find any snippet using google. There is plenty about multi-values examples, etc... but nothing about inserting image for a 'unknown' contact.
Hmm.. it worries me a bit
Thank You in advance for any hints.
This should work
UIImage *iconImage = [UIImage imageNamed:#"icon.png"];
NSData * data = UIImagePNGRepresentation(iconImage);
ABPersonSetImageData(aContact, (CFDataRef)data, nil);
Thats how I've done it in the past and it works. Basically create the image data and the set it for aContact.
Hope that helps