I have created a person object
ABRecordRef person = ABPersonCreate();
I set the properties of person from my web services. person
has all the properties set, like first name, last name, email id, phone number, address, url etc.
I want to load a map view, with multiple pins, where each particular pin holds the information about a particular person. On the click of each pin, I need to load the ABPersonViewController
class of each person. I am not sure about how to add annotation with the information I have and how a particular pin could hold information about a particular person.
In this case the person may or may not be in my address book, and I don't need to save the person in my address book .
I am really confused about how to do this. Need help.
Edit:
I have 3 classes:
!. Web service
class: where I have the person object.
2. MapView
class: where I load the map view.
3. Annotation
class: which has the details about my annotation.
How will I use person records and present it through ABPersonViewController
. How should my annotation
class be?
What I would do to start is create a
Person
class (subclass ofNSObject
) that also implements theMKAnnotation
protocol. You could create two separate classes ("Person" and "PersonAnnotation") if you wanted to but it's not necessary.In the
Person
class, you could either declare your own person-related properties such as First Name, Last Name, Email Address, etc. or you could just have anABRecordRef
ivar and let it store the individual fields for you.I would only create an
ABPerson
record when I want to actually show theABPersonViewController
to keep the AB-specific code isolated and to manage theABPerson
record's creation and release more easily. Regardless, just creating anABRecordRef
does not add it to the address book. As the ABPerson Reference documentation says:So the
Person
class could look like this:The web service class would create an instance of
Person
and set the properties. Then the map view class would add that instance directly to the map (since Person already implements MKAnnotation):When the pin is tapped, the map view will call the
didSelectAnnotationView
delegate method. Or, you could add a disclosure button to the annotation's callout inviewForAnnotation
and respond to that in thecalloutAccessoryControlTapped
delegate method.Whichever action method you decide to use, in that method you could then create an
ABRecordRef
, set its values from the annotation object, and then show theABPersonViewController
. In both delegate methods, thePerson
annotation object could be retrieved using: