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 15417
공지 [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 174696
1380 델파이 XE2에서 dbExpress를 이용해 오라클 연결하기 file 박병일 2012.02.15 17721
1379 이 달의 기술자료 - 2014년 4월 file 험프리 2014.04.03 16811
1378 다중 클라이언트를 위한 DataSnap 서버 만들기 관리자 2011.12.22 16116
1377 "Could not load SSL library." 오류 대응(XE7: BaaS, RESTClient, DataSnap) [1] Humphery 2014.09.12 15981
1376 RAD 스튜디오 모바일 개발 환경 설정(안드로이드, iOS) [1] file 험프리 2014.05.19 15952
1375 이 달의 기술자료 - 2015년 03월 험프리 2015.02.25 15872
1374 델파이 XE2 로 아이폰 하드웨어 컨트롤 하기 박병일 2012.01.19 15502
1373 델파이XE2의 VCL Styles 활용하기 박병일 2012.01.19 15363
1372 [REST API] REST API 이해하기 험프리 2017.05.23 15256
1371 이 달의 기술자료 - 2015년 02월 file 험프리 2015.01.29 15052
» 파이어몽키 기반의 아이폰앱 개발에서 주소록 가져오기 박병일 2012.01.25 14431
1369 dbExpress 의 SQLConnection 에서 트랜젝션 처리하기 박병일 2012.02.08 13974
1368 델파이 XE2로 만든 아이폰 앱 - TicTacToe file 박병일 2012.01.17 13959
1367 파이어몽키 3D Text Editor file 박병일 2012.02.06 13922
1366 델파이 XE2의 DataSnap 서버와 OSX Client의 연동 박병일 2012.01.19 13545
1365 [델파이 문법 시리즈] #1. 제네릭 - 개요 file 관리자 2012.03.21 13165
1364 델파이 XE2로 아이폰앱 만들기 박병일 2012.01.18 13050