gpt4 book ai didi

ios - 从本地联系人获取详细信息后如何区分电话号码

转载 作者:行者123 更新时间:2023-11-29 00:31:40 26 4
gpt4 key购买 nike

我正在使用以下方法获取手机联系人

-(void)fetchContactsandAuthorization
{
// Request authorization to Contacts
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES)
{
//make sure that you have added the necessary properties
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactPostalAddressesKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];

NSLog(@"new %@",cnContacts);

if (error)
{
NSLog(@"error fetching contacts %@", error);
}
else
{
NSString *phone;
NSString *fullName;
NSString *firstName;
NSString *lastName;
NSString *companyName;
NSString *departmentName;
NSString *jobTitleName;
NSString *address;
NSString *iden;
NSString *emailAddress;

UIImage *profileImage;

NSMutableArray *contactNumbersArray = [[NSMutableArray alloc]init];
NSMutableArray *addressArray = [[NSMutableArray alloc]init];
NSMutableArray *emailAddressArray = [[NSMutableArray alloc]init];
for (CNContact *contact in cnContacts) {
// copy data to my custom Contacts class.
firstName = contact.givenName;
lastName = contact.familyName;
iden = contact.identifier;


if (lastName == nil) {
fullName=[NSString stringWithFormat:@"%@",firstName];
}else if (firstName == nil){
fullName=[NSString stringWithFormat:@"%@",lastName];
}
else{
fullName=[NSString stringWithFormat:@"%@ %@",firstName,lastName];
}
UIImage *image = [UIImage imageWithData:contact.imageData];

NSLog(@"imgold %@",image);
if (image != nil) {
profileImage = image;
}else{
profileImage = [UIImage imageNamed:@"person-icon.png"];
}
for (CNLabeledValue *label in contact.phoneNumbers) {
phone = [label.value stringValue];
if ([phone length] > 0) {
[contactNumbersArray addObject:phone];
}
}
NSLog(@"PhonenumberArray %@",contactNumbersArray);


User *user = [User new];
user.fullName=fullName;
user.image= profileImage;
user.phone= phone;
user.idUser= iden;
[contacts addObject:user];

}
dispatch_async(dispatch_get_main_queue(), ^{
[_selectContactListTblView reloadData];
});
}
}
}];
}

我能够获取与联系人关联的所有电话号码并能够存储在一个数组中。

PhonenumberArray (
"98708\U00a001224",
"98920\U00a077702",
"93240\U00a077702",
1,
2,
3,
4,
5,
5,
6,
7,
8,
9
)

现在我想区分数组中的电话号码,如家庭、手机、传真、寻呼机等。非常感谢任何帮助。

最佳答案

CNLabeledValue label 属性将返回一个代表家庭、移动等的字符串。然后调用 [CNLabeledValue localizedStringForLabel:labelString]获取本地化的人类可读字符串。

for (CNLabeledValue *label in contact.phoneNumbers) {
phone = [label.value stringValue];
labelString = label.label;
if ([phone length] > 0) {
[contactNumbersArray addObject:phone];
[contactNumbersLabelsArray addObject:labelString];
}

关于ios - 从本地联系人获取详细信息后如何区分电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41607241/

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