Should I use ABPersonViewController or ABUnknownPersonViewController - iphone

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

Related

UILabel in different subviews

I'm creating my first app. It will be a catalog of products, that you can scroll through.
I created a UIScrollView with a width of 960 (320*3) and added a UIPageControl. Inside it I added 3 different view, each of them represents one of my products - with all the information I need - name, image, description, price, etc..
I can see the views move, and so I've set the first product with UILabel classes and UIImageView. I was wondering if it is possible to use NSArray and set the UILabel's text property and imageNamed in the next view as the user switches to it.
My problem is that each view has a different UILabel element.
Thanks for your help, it is much appreciated!
Yes you could use a NSArray to store the data for each of your views. I would suggest first creating a simple object with the properties labelText and imageName;
Then you can create a NSArray of your custom object like this:
MyObject obj1 = [MyObject new];
obj1.labelText = #"My Text 1";
obj1.imageName = #"My Image 1";
//Other objects..
then
NSArray *myArray = [[NSArray alloc] initWithObjects: obj1, obj2, obj3, nil];
Then When you switch pages simply do this:
MyObject *myPageInfo = [myArray objectAtIndex:pageNumber];
myLabel.text = myPageInfo.labelText;
mylabel.imageName = myPageInfo.imageName;
Hope that helps.

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

how to hide some properties using ABPeoplePicker

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]