1

我知道如何呼叫联系人视图,但如果有人能告诉我如何呼叫特定联系人。要调用视图,我正在调用此方法

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];

我正在获取信息并将其存储到 plist

+ (NSInteger) exportContacts
{

    ABAddressBookRef addressBook = ABAddressBookCreate();

    __block BOOL accessGranted = NO;

    if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6

        dispatch_semaphore_t sema = dispatch_semaphore_create(0);

        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
            accessGranted = granted;
            dispatch_semaphore_signal(sema);
        });

        dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
        dispatch_release(sema);
    }
    else { // we're on iOS 5 or older
        accessGranted = YES;
    }

    NSMutableArray *array = [[NSMutableArray alloc] init];

    if (accessGranted) {

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);

    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);


    for( int i = 0 ; i < nPeople ; i++ )
    {


        NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];

        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i );


        // First Name
        NSString *fName = (__bridge NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty);

        // Record Id

        int recid = ABRecordGetRecordID(ref);
        NSLog(@"Record Id %d",recid);

        // Last Name
        NSString *lName = (__bridge NSString*)ABRecordCopyValue(ref, kABPersonLastNameProperty);

        // Phone
        ABMultiValueRef phoneMultiValue = ABRecordCopyValue(ref, kABPersonPhoneProperty);
        CFArrayRef allPhones = ABMultiValueCopyArrayOfAllValues(phoneMultiValue);
        NSMutableArray *phoneData = [NSMutableArray arrayWithArray:(__bridge NSArray*) allPhones];

        // Email
        ABMultiValueRef emailMultiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
        CFArrayRef allEmails = ABMultiValueCopyArrayOfAllValues(emailMultiValue);
        NSMutableArray *emailData = [NSMutableArray arrayWithArray:(__bridge NSArray*) allEmails];


        // Address
        ABMultiValueRef addressMultiValue = ABRecordCopyValue(ref, kABPersonAddressProperty);
        CFArrayRef allAddresses = ABMultiValueCopyArrayOfAllValues(addressMultiValue);
        NSMutableArray* addressData = [NSMutableArray arrayWithArray:(__bridge NSArray*) allAddresses];



        for ( int j = 0 ; j < [addressData count]; j++) {
            if ([[addressData objectAtIndex:j] count] > 0) {

                if ([fName length] > 0 || [lName length] > 0) {


                    if ([fName length] > 0) {
                        [dic setObject:fName forKey:@"FirstName"];            
                    }

                    if ([lName length] > 0) {
                        [dic setObject:lName forKey:@"LastName"];
                    }

                    if ([phoneData count] > 0) {
                        [dic setObject:phoneData forKey:@"MultiplePhoneNumbers"];
                    }

                    if ([emailData count] > 0) {
                        [dic setObject:emailData forKey:@"MultipleEmails"];
                    }

                    [dic setObject:addressData forKey:@"MultipleAddresses"];

//                   store the ref id here



                    NSLog(@"%@",addressData);
                }
            }
        }

        NSUInteger keyCount = [[dic allKeys] count];
        if (keyCount > 0) {

            [dic setObject:[NSString stringWithFormat:@"%d",i] forKey:@"ab_id"];
            [dic setObject:[NSNumber numberWithBool:FALSE] forKey:@"is_coordinate_fetch"];
            [array addObject:dic];
        }

    }
    [ApplicationUtility setPlistDataWithKey:KEY_ADDRESS_BOOK WithObject:array];
    }
    return [array count];
}
4

1 回答 1

0

查看ABPersonViewController 类参考

于 2013-06-26T14:41:33.430 回答