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 50284
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 48074
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 51027
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 55938
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 65982
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 51571
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 80807
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 211572
43 [발표자료] 20170623 최신OS와 멀티플랫폼 개발 전략 with RAD Studio 관리자 2020.07.22 480
42 [개발팁] TBooleanHelper.ToString 그리고 TUseBoolStrs 관리자 2019.10.21 480
41 [발표자료] 20171117 델파이/C++빌더 제조/제어 개발 세미나 관리자 2017.11.20 479
40 [베를린 U2] 윈도우 10 스토어에 배포하기 (1분 동영상) 험프리 2016.11.15 478
39 [무료 온라인 세미나] 사물인터넷 실제 구현하기 DeepDive! 관리자 2015.09.15 476
38 [엠바카데로 Feature Friday][개발팁] 윈도우 10에서 VCL로 높은 DPI 애플리케이션 개발하기 관리자 2019.06.28 475
37 함께 축하해요! 델파이 25주년!! #Delphi25th file 관리자 2020.02.14 471
36 [UX Summit 요약 / 사례연구] 모바일은 두 번째: 어떨 때 데스크톱에 우선 집중하는가? 관리자 2020.10.22 467
35 RAD스튜디오와 델파이 – 원조 로우코드! 관리자 2020.10.23 466
34 [발표자료] 2015년 12월 C++ Skill Sprints 온라인 세미나 시리즈 관리자 2015.12.30 466
33 RAD서버 활용하기 (엠바카데로 아카데미 코스) 관리자 2020.01.06 462
32 오래된 C++ 프로젝트 마이그레이션 하기 관리자 2019.09.05 462
31 이 달의 기술자료 - 2020년 02월 험프리 2020.01.31 455
30 [다시보기] 전세계 개발자를 위한 컨퍼런스! CodeRage 2018 file 관리자 2018.11.29 455
29 [코드레이지11] Debug faster. Debug smarter - Primož Gabrijelčič 험프리 2016.11.22 454
28 델파이로 개발된 '3D Train Studio'가 BizWireTV의 'Startup Standout' 분야에 선정되었습니다. file 관리자 2017.03.14 451
27 [엠바카데로 UX SUMMIT] 눈여겨 봐야할 컨텐츠들! 관리자 2020.10.06 450
26 검사(Audits)와 측정(Metrics) 기능을 이용 소스코드 표준과 규약 준수를 측정하고 개선할 수 있습니다. 험프리 2020.03.06 448
25 [업데이트][패치][10.3.3] C++빌더 10.3.3 스레딩 및 TLS 패치 험프리 2020.02.03 448
24 데브기어 기술레터 - 2017년 1월 관리자 2016.12.30 448