Vælg telefonnummer fra adressebogen

Sådan her kan man vælge et telefonnummer fra adressebogen.

// link with the following frameworks:
//  AddressBook
//  AddressBookUI

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

/* this method starts the picking */
– (void)pickPhoneNumber
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
    picker.peoplePickerDelegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

/* yes, show details */
– (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    return YES;
}

/* get the value and don’t perform the associated action (i.e. dial) */
– (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
    shouldContinueAfterSelectingPerson:(ABRecordRef)person
    property:(ABPropertyID)property
    identifier:(ABMultiValueIdentifier)identifier
{
    ABMultiValueRef phoneProperty = ABRecordCopyValue( person, property );
    NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex( phoneProperty,identifier );
    
    // DO SOMETHING WITH PHONE NUMBER
    [phone release];
    
    [self dismissModalViewControllerAnimated:YES];
    return NO;
}

/* just dismiss on cancel */
– (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    [self dismissModalViewControllerAnimated:YES];
}

Skriv en kommentar

 
Af Jens Willy Johannsen
jens@greenerpastures.dk
+45 70 26 00 69