iOS打开特定的联系信息

时间:2013-05-20 14:43:49

标签: ios abaddressbook

我知道如何拨打联系人视图,但有人可以告诉我如何拨打特定联系人。 要调用视图,我调用此方法

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];
}

1 个答案:

答案 0 :(得分:0)