2017-03-14 3 views
2

네이티브 CNContactViewController를 사용하여 연락처를 추가하고 연락처를 ': ABPerson'접미사로 반환하고 연락처를 교차 체크하면 동일한 연락처가 다른 식별자와 함께 나타납니다.연락처 식별자가 ABPerson 접미사와 함께 반환됩니다.

실제 연락처 식별자를 얻는 방법을 아는 사람이 있습니까?

코드 만들기 :

- (IBAction)didSelectedAddContact:(id)sender { 
CNMutableContact *contact = [CNMutableContact new]; 

CNContactViewController *contactController = [CNContactViewController viewControllerForNewContact:contact]; 

NSLog(@"contact id : %@", contact.identifier); 

contactController.allowsEditing = true; 
contactController.allowsActions = true; 

contactController.delegate = self; 
[self.navigationController pushViewController:contactController animated:YES];  
} 

위임 콜백 : 함수가 반환 아래

- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact{ 
_contact = contact; 

    [viewController.navigationController popViewControllerAnimated:YES]; 
} 

는 nil을 :

- (CNContact*) getContactFromStoreForIdentifier:(NSString*) identifier 
{ 
    CNContact *updatedContact = nil; 

    id descriptor = [CNContactViewController descriptorForRequiredKeys]; 

CNContactStore *store = [CNContactStore new]; 

NSError *error; 

updatedContact = [store unifiedContactWithIdentifier:identifier 
             keysToFetch:@[descriptor] 
               error:&error]; 
// Found? 
if (updatedContact == nil) 
{ 
    if (error != nil) 
    { 

    } 
} 
return updatedContact; } 

@parameter : CNContact 객체의 식별자 didCompleteWithContact에서 수신 : 위임 콜백 .

+0

당신이'CNContactViewController'를 만드는 코드를 공유하고 대리자 메서드를 구현할 수 있습니다. –

+0

@JonRose가 내 질문을 업데이트했습니다. –

답변

0

viewController에 대해 contactStore를 설정해야합니다. 이 속성이 설정되어 있지 않은 경우

CNContactStore *store = [CNContactStore new]; 
contactController.contactStore = store; 

는 사용자의 연락처에 연락처를 추가하는 대신 사용할 수 없습니다.

소스 : https://developer.apple.com/reference/contactsui/cncontactviewcontroller/1616912-contactstore

+0

고마워요 @ 존,하지만 이것은 잘 작동하지 않았고 마침내 영구 연락처 식별자로 매장에서 새롭게 추가 된 연락처를 얻기 위해 술어를 사용해야했습니다. –

+0

@ R.S. 나는 같은 문제에 직면하고있다. 다른 식별자가있을 때 여기에서 어떻게 관리 할 수 ​​있습니까? 영구적 인 연락처 식별자 란 무엇입니까? –