//获取通讯录中的所有属性,并存储在 textView 中,已检验,切实可行。兼容io6 和 ios 7 ,而且ios7还没有权限确认提示。
-()getAddressBook{ ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook); ( i = ; i < CFArrayGetCount(results); i++) { ABRecordRef person = CFArrayGetValueAtIndex(results, i); NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty); (personName != nil) textView.text = [textView.text stringByAppendingFormat:,personName]; NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty); (lastname != nil) textView.text = [textView.text stringByAppendingFormat:,lastname]; NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty); (middlename != nil) textView.text = [textView.text stringByAppendingFormat:,middlename]; NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty); (prefix != nil) textView.text = [textView.text stringByAppendingFormat:,prefix]; NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty); (suffix != nil) textView.text = [textView.text stringByAppendingFormat:,suffix]; NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty); (nickname != nil) textView.text = [textView.text stringByAppendingFormat:,nickname]; NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty); (firstnamePhonetic != nil) textView.text = [textView.text stringByAppendingFormat:,firstnamePhonetic]; NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty); (lastnamePhonetic != nil) textView.text = [textView.text stringByAppendingFormat:,lastnamePhonetic]; NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty); (middlenamePhonetic != nil) textView.text = [textView.text stringByAppendingFormat:,middlenamePhonetic]; NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty); (organization != nil) textView.text = [textView.text stringByAppendingFormat:,organization]; NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty); (jobtitle != nil) textView.text = [textView.text stringByAppendingFormat:,jobtitle]; NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty); (department != nil) textView.text = [textView.text stringByAppendingFormat:,department]; NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty); (birthday != nil) textView.text = [textView.text stringByAppendingFormat:,birthday]; NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty); (note != nil) textView.text = [textView.text stringByAppendingFormat:,note]; NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty); NSLog(,firstknow); NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty); NSLog(,lastknow); ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty); emailcount = ABMultiValueGetCount(email); ( x = ; x < emailcount; x++) { NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x)); NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x); textView.text = [textView.text stringByAppendingFormat:,emailLabel,emailContent]; } ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty); count = ABMultiValueGetCount(address); ( j = ; j < count; j++) { NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j); textView.text = [textView.text stringByAppendingFormat:,addressLabel]; NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j); NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey]; (country != nil) textView.text = [textView.text stringByAppendingFormat:,country]; NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey]; (city != nil) textView.text = [textView.text stringByAppendingFormat:,city]; NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey]; (state != nil) textView.text = [textView.text stringByAppendingFormat:,state]; NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey]; (street != nil) textView.text = [textView.text stringByAppendingFormat:,street]; NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey]; (zip != nil) textView.text = [textView.text stringByAppendingFormat:,zip]; NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey]; (coutntrycode != nil) textView.text = [textView.text stringByAppendingFormat:,coutntrycode]; } ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty); datescount = ABMultiValueGetCount(dates); ( y = ; y < datescount; y++) { NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y)); NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y); textView.text = [textView.text stringByAppendingFormat:,datesLabel,datesContent]; } CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty); (recordType == kABPersonKindOrganization) { NSLog(); } { NSLog(); } ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty); ( l = ; l < ABMultiValueGetCount(instantMessage); l++) { NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l); textView.text = [textView.text stringByAppendingFormat:,instantMessageLabel]; NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l); NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey]; (username != nil) textView.text = [textView.text stringByAppendingFormat:,username]; NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey]; (service != nil) textView.text = [textView.text stringByAppendingFormat:,service]; } ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty); ( k = ; k< ABMultiValueGetCount(url); m++) { NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m)); NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m); textView.text = [textView.text stringByAppendingFormat:,urlLabel,urlContent]; } NSData *image = (NSData*)ABPersonCopyImageData(person); UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )]; [myImage setImage:[UIImage imageWithData:image]]; myImage.opaque = YES; [textView addSubview:myImage]; } CFRelease(results); CFRelease(addressBook);}