我正在使用 Native CNContactViewController 添加联系人,一旦保存了联系人,它就会返回带有“: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];
}
Run Code Online (Sandbox Code Playgroud)
委托回调:
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact{
_contact = contact;
[viewController.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
下面的函数返回 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];
// …Run Code Online (Sandbox Code Playgroud)