iOS: Add address to new or existing contact with ABUnknownPersonViewController

249 Views Asked by At

Hello everyone,

I am using the a LocationManager, Geocoder and Placemark to get the address of the user. Everything works fine.

After starting standardUpdates I use the following function:

[...]

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

    CLLocation* location = [locations lastObject];
    [self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {

    if (error == nil && [placemarks count] > 0) {
        self.placemark = [placemarks lastObject];

    NSString *placemarkCountry = self.placemark.country;
    NSString *placemarkPostalCode = self.placemark.postalCode;
    NSString *placemarkAdministrativeArea = self.placemark.administrativeArea;
    NSString *placemarkLocality = self.placemark.locality;
    NSString *placemarkThoroughfare = self.placemark.thoroughfare;
    NSString *placemarkSubThoroughfare = self.placemark.subThoroughfare;

    [...] //here I'm displaying the address, nothing special

}

Now I want to use an ABUnknownPersonViewController with AddressBookUI to add the address to a new or existing contact.

-(IBAction)addAddressToContactButtonPressed {

    [...]

}

The following picture shows, what it should looks like:

enter image description here

Question: How the function addAddressToContactButtonPressed should look like? Can you help me with this? The function should use the NSStrings placemarkCountry, placemarkPostalCode, ... and open the ABUnknownPersonViewController with those information. The user should create a new contact with this address or add this address to a existing user.

I looked for some tutorials but couldn't find any useful (for me useful) help. I am a person learning by looking for tutorials and now I'm stuck.

Thank you for your help and your answers.
:-)
1

There are 1 best solutions below

2
On
  1. Make an ABUnknownPersonViewController. Give it a delegate.

  2. Create an ABPerson. Assign to that ABPerson (an ABRecord) any features you want it to have: in this case, the address.

  3. Make the ABPerson the ABUnknownPersonViewController's displayedPerson.

  4. Push the ABUnknownPersonViewController onto an existing UINavigationController.