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
Personclass (subclass ofNSObject) that also implements theMKAnnotationprotocol. You could create two separate classes ("Person" and "PersonAnnotation") if you wanted to but it's not necessary.In the
Personclass, you could either declare your own person-related properties such as First Name, Last Name, Email Address, etc. or you could just have anABRecordRefivar and let it store the individual fields for you.I would only create an
ABPersonrecord when I want to actually show theABPersonViewControllerto keep the AB-specific code isolated and to manage theABPersonrecord's creation and release more easily. Regardless, just creating anABRecordRefdoes not add it to the address book. As the ABPerson Reference documentation says:So the
Personclass could look like this:The web service class would create an instance of
Personand 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
didSelectAnnotationViewdelegate method. Or, you could add a disclosure button to the annotation's callout inviewForAnnotationand respond to that in thecalloutAccessoryControlTappeddelegate 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, thePersonannotation object could be retrieved using: