地址簿(Address Book)使用例子

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef peopleWithName = ABAddressBookCopyPeopleWithName
(addressBook, (CFStringRef)@"name");
if((int)CFArrayGetCount(peopleWithName)){
	CFIndex theIndex= 0;
	ABRecordRef personRecord = CFArrayGetValueAtIndex(peopleWithName, theIndex);
	
       //kABPersonPhoneProperty to get phone number
       //ABMultiValueRef eMails= ABRecordCopyValue(personRecord,kABPersonEmailProperty);
	ABMultiValueRef phoneNumbers= ABRecordCopyValue(personRecord, kABPersonPhoneProperty);
       if(ABMultiValueGetCount(phoneNumbers)){
	       CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneNumbers, 0);						
	       if(phoneNumber!=nil){
			//TODO:to save the phone number
			//release the Phone Number						
			CFRelease(phoneNumber);
		}
	}
	CFRelease(phoneNumbers);
}
CFRelease(peopleWithName);
CFRelease(addressBook);
 

你可能感兴趣的:(iOS开发)