gpt4 book ai didi

objective-c - CNContactStore 通过电子邮件地址检索联系人

转载 作者:太空狗 更新时间:2023-10-30 04:00:53 27 4
gpt4 key购买 nike

我想使用联系人框架 (IOS 9) 来检索与电子邮件地址匹配的联系人。

任何帮助将不胜感激。请使用 Objective-C 。谢谢。

最佳答案

  1. 添加 Contacts.framework
  2. #import <Contacts/Contacts.h>
  3. 编写代码
-(void)loadContactList {
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if( status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted)
{
NSLog(@"access denied");
}
else
{
//Create repository objects contacts
CNContactStore *contactStore = [[CNContactStore alloc] init];
//Select the contact you want to import the key attribute ( https://developer.apple.com/library/watchos/documentation/Contacts/Reference/CNContact_Class/index.html#//apple_ref/doc/constant_group/Metadata_Keys )

NSArray *keys = [[NSArray alloc]initWithObjects:CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, CNContactViewController.descriptorForRequiredKeys, nil];

// Create a request object
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys];
request.predicate = nil;

[contactStore enumerateContactsWithFetchRequest:request
error:nil
usingBlock:^(CNContact* __nonnull contact, BOOL* __nonnull stop)
{
// Contact one each function block is executed whenever you get
NSString *phoneNumber = @"";
if( contact.phoneNumbers)
phoneNumber = [[[contact.phoneNumbers firstObject] value] stringValue];

NSLog(@"phoneNumber = %@", phoneNumber);
NSLog(@"givenName = %@", contact.givenName);
NSLog(@"familyName = %@", contact.familyName);
NSLog(@"email = %@", contact.emailAddresses);


[contactList addObject:contact];
}];

[contactTableView reloadData];
}

}

关于objective-c - CNContactStore 通过电子邮件地址检索联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32835853/

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