IOS: Address Book (18-01-17), ios Address Book 18-01-17

Source: Internet
Author: User

IOS: Address Book (18-01-17), ios Address Book 18-01-17

1. Read the address book

1) Before 9.0

2) After 9.0

2. Call the communication recording UI

1) Before 9.0

2) After 9.0

3. Reference

 

0. Preface

Plist needs to set privacy Permissions

Privacy-Contacts Usage Description: Access Address Book (custom)

1. Read the address book

1) Before 9.0

1-1) header file

#import <AddressBook/AddressBook.h>

1-2) Determine if you have permissions

-(Void) Authorization {// determine whether to authorize ABAuthorizationStatus authorizationStatus = Authorization (); if (authorizationStatus = Authorization) {// request to authorize ABAddressBookRef addressBookRef = abaddressbookcreatewitexceptions (NULL, NULL ); ABAddressBookRequestAccessWithCompletion (addressBookRef, ^ (bool granted, CFErrorRef error) {if (granted) {// The authorization succeeds [self readAddressBook];} else {// NSLog (@ "prompt: the user canceled the authorization and failed to read ") ;}}) ;}else if (authorizationStatus = kABAuthorizationStatusAuthorized) {// authorized [self readAddressBook];} else {dispatch_async (dispatch_get_main_queue (), ^ {// NSLog (@ "prompt: ");});}}

1-3) read and save the model (not done)

-(Void) readAddressBook {// obtain all contacts ABAddressBookRef addressBookRef = ABAddressBookCreate (); // obtain all contact data CFArrayRef peoples = ABAddressBookCopyArrayOfAllPeople (addressBookRef ); // obtain the number of all contacts CFIndex peoplesCount = ABAddressBookGetPersonCount (addressBookRef); for (int I = 0; I <peoplesCount; I ++) {// obtain the reference of the contact object ABRecordRef people = CFArrayGetValueAtIndex (records Les, I); // obtain the name of the current contact NSString * firstName = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonFirstNameProperty); // obtain the last name of the current contact NSString * lastName = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonLastNameProperty); NSLog (@ "Hangzhou (@"--------------------------------------------------"); NSLog (@ "firstName = % @, lastName = % @", firstName, lastName); // obtain the intermediate name of the current contact NSString * middleName = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonMiddleNameProperty); // obtain the name prefix of the current contact NSString * prefix = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonPrefixProperty )); // obtain the name suffix NSString * suffix = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonSuffixProperty) of the current contact )); // obtain the nickName NSString * nickName = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonNicknameProperty) of the current contact )); // obtain the name of the current contact NSString * firstNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonFirstNamePhoneticProperty )); // obtain the last name of the current contact NSString * lastNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonLastNamePhoneticProperty )); // obtain the intermediate name of the current contact NSString * middleNamePhoneic = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonMiddleNamePhoneticProperty )); // obtain the company NSString * organization = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonOrganizationProperty) of the current contact )); // obtain the current contact's position NSString * job = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonJobTitleProperty )); // obtain the department NSString * department = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonDepartmentProperty) of the current contact )); // obtain the current contact's birthday NSDate * birthday = (_ bridge NSDate *) (ABRecordCopyValue (people, kABPersonBirthdayProperty )); // obtain the remarks of the current contact NSString * notes = (_ bridge NSString *) (ABRecordCopyValue (people, kABPersonNoteProperty )); // obtain the current contact profile image NSData * userImage = (_ bridge NSData *) (ABPersonCopyImageData (people); // obtain the kind value CFNumberRef kindType = ABRecordCopyValue (people, kABPersonKindProperty ); if (kindType = kABPersonKindOrganization) {NSLog (@ "");} else {// it's a person, resource, or room NSLog (@ "");} // obtain the time when the current contact is created. Note that NSDate * creatTime = (_ bridge NSDate *) (ABRecordCopyValue (people, kABPersonCreationDateProperty )); // obtain the time NSDate * alterTime = (_ bridge NSDate *) (ABRecordCopyValue (people, kABPersonModificationDateProperty) of the Last Modified contact )); // obtain the current contact's phone array pai* phoneArray = [[financialloc] init]; ABMultiValueRef phones = ABRecordCopyValue (people, kABPersonPhoneProperty); CFIndex phonesCount = ABMultiValueGetCount (phones ); for (NSInteger j = 0; j <phonesCount; j ++) {// obtain the call Label NSString * phoneLabel = (_ bridge NSString *) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (phones, j); // obtain the telephone value NSString * phone = (_ bridge NSString *) (ABMultiValueCopyValueAtIndex (phones, j) under the Label )); NSLog (@ "phone = % @", phone); [phoneArray addObject: phone];} // obtain IM multi-value NSMutableArray * instantMessageArray = [[NSMutableArray alloc] init]; ABMultiValueRef instantMessages = ABRecordCopyValue (people, messages); CFIndex instantMessagesCount = ABMultiValueGetCount (instantMessages); for (int j = 1; j <instantMessagesCount; j ++) {// obtain IM Label NSString * instantMessageLabel = (_ bridge NSString *) ABMultiValueCopyLabelAtIndex (instantMessages, j ); // obtain IM content NSDictionary * instantMessageContent = (_ bridge NSDictionary *) ABMultiValueCopyValueAtIndex (instantMessages, j); NSString * username = [instantMessageContent valueForKey :( NSString *) encrypted]; NSString * service = [instantMessageContent valueForKey :( NSString *) Response];} // obtain URL multi-value response * urlArray = [[NSMutableArray alloc] init]; ABMultiValueRef urls = ABRecordCopyValue (people, kABPersonURLProperty); CFIndex urlsCount = ABMultiValueGetCount (urls); for (int j = 0; j <urlsCount; j ++) {// obtain the call Label NSString * urlLabel = (_ bridge NSString *) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (urls, j )); // obtain the telephone value NSString * urlContent = (_ bridge NSString *) ABMultiValueCopyValueAtIndex (urls, j) under the Label );} // obtain the email address of the current contact. Note that the array listing * emailArray = [[using alloc] init]; ABMultiValueRef emails = ABRecordCopyValue (people, kABPersonEmailProperty); CFIndex emailsCount = ABMultiValueGetCount ); for (NSInteger j = 0; j <emailsCount; j ++) {// obtain the email Label NSString * emailLabel = (_ bridge NSString *) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (emails, j); // obtain the email value NSString * email = (_ bridge NSString *) (ABMultiValueCopyValueAtIndex (emails, j); NSLog (@ "email = % @", email); [emailArray addObject: email];} // get the address. Note that the array NSMutableArray * addressArray = [[NSMutableArray alloc] init]; ABMultiValueRef addresss = ABRecordCopyValue ); CFIndex addresssCount = ABMultiValueGetCount (addresss); for (int j = 0; j <addresssCount; j ++) {// address type NSString * addressLabel = (_ bridge NSString *) (ABMultiValueCopyLabelAtIndex (addresss, j); NSDictionary * personaddress = (_ bridge NSDictionary *) (ABMultiValueCopyValueAtIndex (addresss, j )); // obtain the address NSString * country = [personaddress valueForKey :( NSString *) kABPersonAddressCountryKey]; NSString * state = [personaddress valueForKey :( NSString *) kABPersonAddressStateKey]; NSString * city = [personaddress valueForKey :( NSString *) region]; NSString * street = [personaddress valueForKey :( NSString *) kABPersonAddressStreetKey]; NSString * zip = [personaddress valueForKey :( NSString *) kABPersonAddressZIPKey]; NSString * coutntrycode = [personaddress valueForKey :( NSString *) kABPersonAddressCountryCodeKey]; // address string, which can be formatted as needed NSString * adress = [NSString stringWithFormat: % @ \ n Province: % @ \ n city: % @ \ n street: % @ \ n zip code: % @ ", country, state, city, street, zip];} // obtain the current contact anniversary * dateArr = [[NSMutableArray alloc] init]; ABMultiValueRef dates = ABRecordCopyValue (people, kABPersonDateProperty); CFIndex datesCount = ABMultiValueGetCount (dates ); for (NSInteger j = 0; j <datesCount; j ++) {// obtain dates Label NSString * dateLabel = (_ bridge NSString *) ABAddressBookCopyLocalizedLabel (ABMultiValueCopyLabelAtIndex (dates, j); // obtain the date of the anniversary NSDate * date = (_ bridge NSDate *) (ABMultiValueCopyValueAtIndex (dates, j )); // obtain the anniversary name NSString * str = (_ bridge NSString *) (ABMultiValueCopyLabelAtIndex (dates, j); NSDictionary * tempDic = [NSDictionary dictionaryWithObject: date forKey: str]; [dateArr addObject: tempDic] ;}}

  

 

 

 
3. Reference

IOS Address Book Development-qianhuang 89

Explanation of four methods for iOS to get address book -- vbirdbest CSDN

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.