-1

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.
:-)
Benjamin1956
  • 1,883
  • 2
  • 12
  • 12

1 Answers1

1
  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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • So you are just going to have to learn, then. You have to walk before you can run. – matt May 18 '15 at 21:12
  • I suppose you could try reading the section of my book that discusses ABUnknownPersonViewController: http://www.apeth.com/iOSBook/ch31.html#_abunknownpersonviewcontroller If you don't understand it, just keep reading the book backwards until you come to something you _do_ understand. – matt May 18 '15 at 21:14