gpt4 book ai didi

ios - 返回带 ABPerson 后缀的联系人标识符

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:31:35 27 4
gpt4 key购买 nike

我正在使用 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];
}

委托(delegate)回调:

- (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:从 didCompleteWithContact 接收到的 CNContact 对象的标识符:委托(delegate)回调。

最佳答案

您必须为 viewController 设置一个 contactStore。

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

If not this property is not set, than adding the contact to the user's contacts is disabled.

来源:https://developer.apple.com/reference/contactsui/cncontactviewcontroller/1616912-contactstore

关于ios - 返回带 ABPerson 后缀的联系人标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42787422/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com