調用通訊錄代碼,由於本人新手,寫此日誌記錄

在.h裏寫代理協議 

,ABPeoplePickerNavigationControllerDelegate


在.m裏的viewload(哪裏需要調用寫在哪裏)寫這段代碼,

ABPeoplePickerNavigationController * picker = [[ABPeoplePickerNavigationController alloc] init];

    [picker setPeoplePickerDelegate:self];

    [self presentViewController:picker animated:YES completion:nil];


實現代理方法

#pragma ABPeoplePickerNavigationController delegate

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person

{

    return YES;

}


- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker

      shouldContinueAfterSelectingPerson:(ABRecordRef)person

                                property:(ABPropertyID)property

                              identifier:(ABMultiValueIdentifier)identifier

{

    if(property == kABPersonPhoneProperty) {

        

        ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, property);

        int index = ABMultiValueGetIndexForIdentifier(phoneMulti,identifier);

        NSString *phone = (NSString*)CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneMulti, index));

kABPersonFirstNameProperty));

        

        NSString * str = [phone stringByReplacingOccurrencesOfString:@"-" withString:@""];

        str = [str stringByReplacingOccurrencesOfString:@"+86" withString:@""];

        str = [str stringByReplacingOccurrencesOfString:@"(" withString:@""];

        str = [str stringByReplacingOccurrencesOfString:@")" withString:@""];

        str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

        

        [_tfPhoneCode setText:str];

        CFRelease(phoneMulti);//C對象的釋放

        [peoplePicker dismissViewControllerAnimated:YES completion:nil];

        

    }

    return NO;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章