2013-02-12 3 views
1

내 프로필의 정보를 iPhone 전화 번호부/연락처 목록에로드하고 싶습니다.프로필 페이지 (전화 번호, 이메일 주소, 사진)에서 연락처 정보를 iOS 전화 번호부 연락처 목록으로 추출 연락처 목록

내 앱에는 전화 번호, 이름, 학교, 교육 수준, 이메일 주소, 사진, 그들이 한 일의 요약, 관심 분야 등 자신이 나타내는 사람들에 대한 다양한 속성을 포함하는 사용자 프로필이 있습니다.

다른 사용자가이 프로필 페이지의 연락처 특성을 한 번 클릭하여 추출하여 iPhone 연락처 목록으로 가져올 수있게하고 싶습니다.

예를 들어 내가 UserA를 좋아하고 iPhone 연락처 목록에 추가하고 싶다면 "연락처에 추가"를 클릭하면 UserA의 관련 프로필 정보 (전화 번호, 이메일 주소, 주소, URL, 사진 등)를 작성하고 iPhoneA 전화 번호부에 새 연락처로 UserA를 만듭니다.

iphone의 abpeoplepicker api를 사용하면 가능합니까? 그렇다면 어떻게 실행해야합니까 (어디에서 적절한 문서를 참조 할 수 있습니까?) 그리고 이것이 가능할 수있는 한계/조건/기준은 무엇입니까?

+1

http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html# // apple_ref/doc/uid/TP40007744-CH5-SW6 –

+0

감사합니다. 여기에 사진 추출이 포함되어 있습니까? –

답변

1

프레임 워크 :

#import "AddressBook/AddressBook.h" 

코드 :

- (void) getLocalContacts 
{ 
    ABAddressBookRef addressBook = ABAddressBookCreate(); 
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); 
    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); 

    User *user; 
    NSMutableArray *allContacts = [[NSMutableArray alloc] init]; 

    for (int i = 0; i < nPeople; i++) 
    { 
     ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i); 

     ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty); 

     if(ABMultiValueGetCount(emails) != 0) 
     { 
      user = [[User alloc] init]; 

      CFStringRef fName, lName; 
      fName = ABRecordCopyValue(person, kABPersonFirstNameProperty); 
      lName = ABRecordCopyValue(person, kABPersonLastNameProperty); 

      CFStringRef email = ABMultiValueCopyValueAtIndex(emails, 0); 


      NSData *imgData = (NSData *)ABPersonCopyImageData(person); 



      NSString *firstName = (NSString *) fName; 
      NSString *lastName = (NSString *) lName; 


      if (firstName.length == 0 && lastName.length != 0){ 
       user.userName = lastName; 
      } 
      else if (firstName.length != 0 && lastName.length == 0){ 
       user.userName = firstName; 
      } 
      else if (firstName.length == 0 && lastName.length == 0){ 
       user.userName = @""; 
      } 
      else if (firstName.length != 0 && lastName.length != 0){ 
       user.userName = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; 
      } 


      //user.firstName = (NSString *) firstName; 
      user.lastName = @""; 

      user.email = (NSString *) email; 

      user.firstName = (NSString *) email; 

      user.localImage = [UIImage imageWithData:imgData]; 

      [allContacts addObject:user]; 

      [user release]; 

     } 
    } 

    [DataManager sharedManager].allLocalUsers = allContacts; 

    [self hideSpinner]; 

}