http://blogs.embarcadero.com/ao/2012/01/24/39203


iOS Address Book fun

Getting data out of the iOS address book is a lot harder than I thought… Must make component… ;)

Here’s a Q&D routine I managed to eek out today. It simply prints all contacts and all their numbers to the log console.

Enjoy!

uses
  iPhoneAll, AddressBook, CFArray, CFBase;

procedure DumpAddressBook;
var
  addressBook : ABAddressBookRef;
  allPeople : CFArrayRef;
  nPeople : CFIndex;
  ref : ABRecordRef;
  i, j : Integer;
  firstName : CFStringRef;
  lastName : CFStringRef;
  phoneNumber : CFStringRef;
  l, v : CFStringRef;
  S : NSString;
begin
  addressBook := ABAddressBookCreate;
  allPeople := ABAddressBookCopyArrayOfAllPeople(addressBook);
  nPeople := ABAddressBookGetPersonCount(addressBook);

  for i:=0 to nPeople-1 do begin
    ref := CFArrayGetValueAtIndex(allPeople,i);

    firstName := ABRecordCopyValue(ref,kABPersonFirstNameProperty);
    lastName := ABRecordCopyValue(ref,kABPersonLastNameProperty);
    if firstName <> nil then
      if lastName <> nil then
        S := NSString.stringWithFormat(NSSTR(PChar('%@, %@')),lastName,firstName)
      else
        S := NSString.stringWithFormat(NSSTR(PChar('%@')),firstName)
    else
      if lastName <> nil then
        S := NSString.stringWithFormat(NSSTR(PChar('%@')),lastName);
    NSLog(S);

    phoneNumber := ABRecordCopyValue(ref, kABPersonPhoneProperty);
    for j:=0 to ABMultiValueGetCount(phoneNumber)-1 do begin
      l := ABMultiValueCopyLabelAtIndex(phoneNumber,j);
      v := ABMultiValueCopyValueAtIndex(phoneNumber,j);
      S := NSString.stringWithFormat(NSSTR(PChar('%@: %@')),l,v);
      NSLog(S);
      CFRelease(l);
      CFRelease(v);
    end;

    if phoneNumber <> nil then
      CFRelease(phoneNumber);
    if firstName <> nil then
      CFRelease(firstName);
    if lastName <> nil then
      CFRelease(lastName);
  end;
end;

번호 제목 글쓴이 날짜 조회 수
공지 [DelphiCon 요약] 코드사이트 로깅 실전 활용 기법 (Real-world CodeSite Logging Techniques) 관리자 2021.01.19 14406
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 13046
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 15553
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 21082
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 22315
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 17964
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 38250
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 173767
10 C++빌더와 델파이를 이용한 SHA 해시 file 김원경 2018.05.21 1587
9 [따라하기] 인공지능 오목게임(3) - 디자인 구성하기 file 대화마을 2017.09.14 1613
8 RAD Studio(델파이/C++빌더) 모바일 앱 배포하기 관리자 2017.01.16 743
7 곧 다가올 리눅스를 준비하세요. file 험프리 2016.12.09 850
6 RAD Studio, Delphi 그리고 C++빌더 로드맵 - 한글(2014년 3월) file Humphery 2014.03.05 5541
5 델파이 이전버전을 설치하는 방법 Humphery 2014.02.14 4895
» 파이어몽키 기반의 아이폰앱 개발에서 주소록 가져오기 박병일 2012.01.25 14426
3 델파이XE2 파이어몽키 기반 아이폰앱 개발에서 제스춰를 인식시키는 방법 박병일 2012.01.25 23241
2 델파이XE2의 VCL Styles 활용하기 박병일 2012.01.19 15352
1 델파이 XE2로 만든 아이폰 앱 - TicTacToe file 박병일 2012.01.17 13952