首页 > 其他 > 详细

调用通讯录代码,由于本人新手,写此日志记录

时间:2015-01-21 20:19:55      阅读:241      评论:0      收藏:0      [点我收藏+]

在.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;

}


调用通讯录代码,由于本人新手,写此日志记录

原文:http://zerolee1213.blog.51cto.com/9835168/1606707

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!