네이티브 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에서 수신 : 위임 콜백 .
당신이'CNContactViewController'를 만드는 코드를 공유하고 대리자 메서드를 구현할 수 있습니다. –
@JonRose가 내 질문을 업데이트했습니다. –