2

I'm using ABPeoplePickerNavigationController to show the adress book users, and I return YEs in shouldContinueAfterSelectingPerson to see the user's phone & email.
But when I tap on the phone or email, nothing happens.. and I want it to send sms or email.
Is this something I need to implement by my self?

I also return YES in shouldContinueAfterSelectingPerson, shouldn't it do the work?

user1590031
  • 308
  • 1
  • 5
  • 15

2 Answers2

5

I'm sorry to say you have a lot of work ahead of you. First, once the contact is selected by the user, then you need to extract the phone or email yourself. If there are multiple tel numbers or email addresses, you probably should then prompt the user which one to use - by using a UIActionSheet or a table. With a phone number, you can create a telephone URL and send that to the shared application, which causes a call to be made (there are lots of examples here on how to do that).

With an email address, you need to use MFMailComposeViewController to create an email, and then you add the one known address in for the user through the delegate. There is also a sister class, MFMessageComposeViewController, for sending SMS messages.

I did this exact same thing for my company and it took me about 3 days to code and test the whole thing (all 3 options).

EDIT: A person can have multiple phone numbers and email addresses. You have two choices here:

  • use the delegate method you already are using, return NO, but save the "property" and "identifier" that the user has tapped on. That will be a phone number, email address, etc (it could be a an address too so you need to probe deeper. You can find examples of how to get the exact property with those two values here or elsewhere.

  • you can use "peoplePickerNavigationController:shouldContinueAfterSelectingPerson:" to not show the user the person's attributes, but simply to indicate this is the person they are interested in contacting. With that persons record, you can find out how many email addresses they have, and if its only one then your work is done. If not you have to ask the person to tell you which one. [This is how I did it]

David H
  • 40,852
  • 12
  • 92
  • 138
  • Thanks for your reply, I looked at shouldContinueAfterSelectingPerson docs and it says: "Return YES if you want default action to be performed" what is default action? – user1590031 Sep 02 '12 at 17:42
  • Hmm - interesting - well, I believe what should happen if you return YES is that iOS will switch to the Phone app, Messages, or Mail depending on what you tapped on. A couple of things: you need to have a strong reference to ABPeoplePickerNavigationController after you return YES (so that class is not released before it contacts the system). Did you add a log message so you know you in fact returned YES? Can you log the value too - of what was tapped. Try adding some dummy email addresses in a contact so you know for sure they are properly formatted. Is problem on device or simulator? – David H Sep 02 '12 at 17:51
  • anyway id the default behavior is as u say it's not what I want.. Do you know how do I get the phone number of the contact? – user1590031 Sep 02 '12 at 17:53
1

I agree with what David H said in his answer, you have a lot of work. To try to help you a bit, this will explain to you how to send an SMS.

Also here is a small code snippet that should give you an idea of how to get a phone number from an Address Book record:

ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef record = ABPersonCreate();
ABMutableMultiValueRef multi;
record = ABAddressBookGetPersonWithRecordID(addressBook, contactID);
multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
int multiCount = ABMultiValueGetCount(multi);
for(CFIndex i=0; i<multiCount; i++)
{
    [tempArrayPhones addObject:[NSString stringWithFormat:@"%@", (NSString *)ABMultiValueCopyValueAtIndex(multi, i)]];
}

Again this is not a complete code, it is just a snippet to give you an idea.

Community
  • 1
  • 1
antf
  • 3,162
  • 2
  • 26
  • 33
  • In shouldContinueAfterSelectingPerson I get the person, property and identifier, How can I get the phone number from them? – user1590031 Sep 03 '12 at 06:58
  • Already answered in my answer, it is `ABMultiValueCopyValueAtIndex(multi, i)`. Since a person can have more than one phone number you need to use a `ABMutableMultiValueRef` to get the multiple numbers. – antf Sep 04 '12 at 15:31