通讯录调用及委托实现


#pragma mark - ABPeoplePickerNavigationControllerDelegate

- (void)onChooseContact{
    

    
    UIImage *navigationBarImage = [UIImage imageNamed:@"navigationBarBG.png"];
    navigationBarImage = [ARWImageUtil scaleToSize:navigationBarImage size:CGSizeMake(320, 64)];

    [[UINavigationBar appearance] setBackgroundImage:navigationBarImage forBarMetrics:UIBarMetricsDefault];
    
    [self presentViewController:_peoplePicker animated:YES completion:^(void){}];
    
}


//ios7 =< version <ios8以下,不包含ios8
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED < 80000)


- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    
    ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
    //    ABMutableMultiValueRef address=ABRecordCopyValue(person, kABPersonAddressProperty);
    //    ABMutableMultiValueRef birthday=ABRecordCopyValue(person, kABPersonBirthdayProperty);
    //    ABMutableMultiValueRef creationDate=ABRecordCopyValue(person, kABPersonCreationDateProperty);
    //    ABMutableMultiValueRef date=ABRecordCopyValue(person, kABPersonDateProperty);
    //    ABMutableMultiValueRef department=ABRecordCopyValue(person, kABPersonDepartmentProperty);
    //    ABMutableMultiValueRef email=ABRecordCopyValue(person, kABPersonEmailProperty);
    //    ABMutableMultiValueRef firstNamePhonetic=ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
    //    ABMutableMultiValueRef firstName=ABRecordCopyValue(person, kABPersonFirstNameProperty);
    //    ABMutableMultiValueRef instantMessage=ABRecordCopyValue(person, kABPersonInstantMessageProperty);
    //    ABMutableMultiValueRef jobTitle=ABRecordCopyValue(person, kABPersonJobTitleProperty);
    //    ABMutableMultiValueRef kind=ABRecordCopyValue(person, kABPersonKindProperty);
    //    ABMutableMultiValueRef lastNamePhonetic=ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
    //    ABMutableMultiValueRef lastName=ABRecordCopyValue(person, kABPersonLastNameProperty);
    //    ABMutableMultiValueRef middleNamePhonetic=ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
    //    ABMutableMultiValueRef middleName=ABRecordCopyValue(person, kABPersonMiddleNameProperty);
    //    ABMutableMultiValueRef modificationDate=ABRecordCopyValue(person, kABPersonModificationDateProperty);
    //    ABMutableMultiValueRef nickname=ABRecordCopyValue(person, kABPersonNicknameProperty);
    //    ABMutableMultiValueRef note=ABRecordCopyValue(person, kABPersonNoteProperty);
    //    ABMutableMultiValueRef organization=ABRecordCopyValue(person, kABPersonOrganizationProperty);
    //    ABMutableMultiValueRef phone=ABRecordCopyValue(person, kABPersonPhoneProperty);
    //    ABMutableMultiValueRef prefix=ABRecordCopyValue(person, kABPersonPrefixProperty);
    //    ABMutableMultiValueRef relatedNames=ABRecordCopyValue(person, kABPersonRelatedNamesProperty);
    //    ABMutableMultiValueRef socialProfile=ABRecordCopyValue(person, kABPersonSocialProfileProperty);
    //    ABMutableMultiValueRef personSuffix=ABRecordCopyValue(person, kABPersonSuffixProperty);
    //    ABMutableMultiValueRef _URL=ABRecordCopyValue(person, kABPersonURLProperty);
    
    
    NSMutableArray *phones = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < ABMultiValueGetCount(phoneMulti); i++) {
        
        NSString *aPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, i);
        [phones addObject:aPhone];
    }
    
    NSLog(@"+qqqqqqqqqq++++%@",phones);
    
    
    NSLog(@"****************");
    NSString *mobileNo = [phones objectAtIndex:0];
    
    //    self.label.text = (NSString*)ABRecordCopyCompositeName(person);
    NSLog(@"++++++++++++++++++++%@",mobileNo);
    
    return YES;
}



- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    
    ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString *aPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, identifier);
    
    ABMutableMultiValueRef firstName=ABRecordCopyValue(person, kABPersonFirstNameProperty);
    ABMutableMultiValueRef lastName=ABRecordCopyValue(person, kABPersonLastNameProperty);
    NSLog(@"+qqqqqqqqqq++++%@",aPhone);
    NSLog(@"+FirstName=%@, lastName=%@", firstName, lastName);
    
    [self dismissViewControllerAnimated:YES completion:^(void){}];
    
    return NO;
}

#endif





#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
//- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person
//{
//    
//    ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
//    //    ABMutableMultiValueRef address=ABRecordCopyValue(person, kABPersonAddressProperty);
//    //    ABMutableMultiValueRef birthday=ABRecordCopyValue(person, kABPersonBirthdayProperty);
//    //    ABMutableMultiValueRef creationDate=ABRecordCopyValue(person, kABPersonCreationDateProperty);
//    //    ABMutableMultiValueRef date=ABRecordCopyValue(person, kABPersonDateProperty);
//    //    ABMutableMultiValueRef department=ABRecordCopyValue(person, kABPersonDepartmentProperty);
//    //    ABMutableMultiValueRef email=ABRecordCopyValue(person, kABPersonEmailProperty);
//    //    ABMutableMultiValueRef firstNamePhonetic=ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
//    //    ABMutableMultiValueRef firstName=ABRecordCopyValue(person, kABPersonFirstNameProperty);
//    //    ABMutableMultiValueRef instantMessage=ABRecordCopyValue(person, kABPersonInstantMessageProperty);
//    //    ABMutableMultiValueRef jobTitle=ABRecordCopyValue(person, kABPersonJobTitleProperty);
//    //    ABMutableMultiValueRef kind=ABRecordCopyValue(person, kABPersonKindProperty);
//    //    ABMutableMultiValueRef lastNamePhonetic=ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
//    //    ABMutableMultiValueRef lastName=ABRecordCopyValue(person, kABPersonLastNameProperty);
//    //    ABMutableMultiValueRef middleNamePhonetic=ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
//    //    ABMutableMultiValueRef middleName=ABRecordCopyValue(person, kABPersonMiddleNameProperty);
//    //    ABMutableMultiValueRef modificationDate=ABRecordCopyValue(person, kABPersonModificationDateProperty);
//    //    ABMutableMultiValueRef nickname=ABRecordCopyValue(person, kABPersonNicknameProperty);
//    //    ABMutableMultiValueRef note=ABRecordCopyValue(person, kABPersonNoteProperty);
//    //    ABMutableMultiValueRef organization=ABRecordCopyValue(person, kABPersonOrganizationProperty);
//    //    ABMutableMultiValueRef phone=ABRecordCopyValue(person, kABPersonPhoneProperty);
//    //    ABMutableMultiValueRef prefix=ABRecordCopyValue(person, kABPersonPrefixProperty);
//    //    ABMutableMultiValueRef relatedNames=ABRecordCopyValue(person, kABPersonRelatedNamesProperty);
//    //    ABMutableMultiValueRef socialProfile=ABRecordCopyValue(person, kABPersonSocialProfileProperty);
//    //    ABMutableMultiValueRef personSuffix=ABRecordCopyValue(person, kABPersonSuffixProperty);
//    //    ABMutableMultiValueRef _URL=ABRecordCopyValue(person, kABPersonURLProperty);
//    
//    
//    NSMutableArray *phones = [[NSMutableArray alloc] init];
//    
//    for (int i = 0; i < ABMultiValueGetCount(phoneMulti); i++) {
//        
//        NSString *aPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, i);
//        [phones addObject:aPhone];
//    }
//    
//    NSLog(@"+qqqqqqqqqq++++%@",phones);
//    
//    
//    NSLog(@"****************");
//    NSString *mobileNo = [phones objectAtIndex:0];
//    
//    //    self.label.text = (NSString*)ABRecordCopyCompositeName(person);
//    NSLog(@"++++++++++++++++++++%@",mobileNo);
//    
//    
//}



// Called after a property has been selected by the user.
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    
    ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString *aPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneMulti, identifier);
    
    ABMutableMultiValueRef firstName=ABRecordCopyValue(person, kABPersonFirstNameProperty);
    ABMutableMultiValueRef lastName=ABRecordCopyValue(person, kABPersonLastNameProperty);
    NSLog(@"+qqqqqqqqqq++++%@",aPhone);
    NSLog(@"+FirstName=%@, lastName=%@", firstName, lastName);

    
    [self dismissViewControllerAnimated:YES completion:^(void){}];
    
}

#endif


- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker

{
    [self dismissViewControllerAnimated:YES completion:^(void){}];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值