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 15414
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 13960
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 16496
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 22048
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 23267
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 18921
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 39245
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 174695
1398 N 윈도우와 맥 개발 시작을 위한 파이어몽키 코스북: 무료 다운로드 제공(385페이지) 관리자 2013.04.05 152326
1397 ComPort(시리얼 통신) 컴포넌트 설치안내 [11] file 험프리 2013.12.04 107125
1396 [REST API] REST 기반 파일 업로드와 다운로드 구현하기 험프리 2020.08.31 83031
1395 델파이 튜토리얼 자습서 이용 안내 관리자 2014.09.01 71936
1394 이 달의 기술자료 - 2014년 11월 험프리 2014.10.13 54120
1393 이 달의 기술자료 - 2014년 6월 file 험프리 2014.06.05 50357
1392 Find the O/S Language Type c2design 2014.07.30 47761
1391 RAD Studio Resource Center 박병일 2012.01.26 46451
1390 CD-ROM 열고 닫기 박병일 2011.12.22 44762
1389 [Android] 폰번호 가져오기 [1] 타락천사 2014.09.05 38535
1388 이 달의 기술자료 - 2014년 12월 file 험프리 2014.11.26 32457
1387 RAD Studio XE6 Update1 발표 [1] Humphery 2014.06.20 29462
1386 델파이XE2 파이어몽키 기반 아이폰앱 개발에서 제스춰를 인식시키는 방법 박병일 2012.01.25 23255
1385 [10.4 시드니 신기능] 새로운 VCL TEdgeBrowser 컴포넌트 험프리 2020.05.18 22908
1384 SendMessage 함수를 이용한 메세지 전송 관리자 2012.01.05 18255