gpt4 book ai didi

iphone - 如何仅获取地址簿中具有传真号码的联系人列表?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:23 24 4
gpt4 key购买 nike

我想获取所有具有传真号码的联系人的列表,并且只获取这些联系人。我不想显示任何只有电子邮件或电话号码的联系人。

最佳答案

如果您还没有浏览 ABAddressBook Reference

遍历通讯录的所有记录,得到kABPersonPhoneProperty。这是一个多值属性,因此遍历其所有标签。如果存在工作传真 (kABPersonPhoneWorkFAXLabel) 或家庭传真 (kABPersonPhoneHomeFAXLabel) 标签,请获取这些值。

下面是一些简单的示例代码:

ABAddressBookRef addressBook = ABAddressBookCreate();

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for( CFIndex personIndex = 0; personIndex < nPeople; personIndex++ ) {
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, personIndex );
CFStringRef name = ABRecordCopyCompositeName( person );
ABMultiValueRef phones = ABRecordCopyValue( person, kABPersonPhoneProperty );
NSString* homeFax = nil;
NSString* workFax = nil;
BOOL hasFax = NO;
for( CFIndex phoneIndex = 0; phoneIndex < ABMultiValueGetCount( phones ); phoneIndex++ ) {
NSString* aLabel = (NSString*) ABMultiValueCopyLabelAtIndex( phones, phoneIndex );
if( [aLabel isEqualToString:(NSString*)kABPersonPhoneHomeFAXLabel] ) {
homeFax = (NSString*) ABMultiValueCopyValueAtIndex( phones, phoneIndex );
hasFax = YES;
}
else if( [aLabel isEqualToString:(NSString*)kABPersonPhoneWorkFAXLabel]) {
workFax = (NSString*) ABMultiValueCopyValueAtIndex( phones, phoneIndex );
hasFax = YES;
}
[aLabel release];
}
if( hasFax ) {
NSLog( @"%@: %@, %@", name,
homeFax == nil ? @"" : homeFax,
workFax == nil ? @"" : workFax );
if( homeFax ) [homeFax release];
if( workFax ) [workFax release];
}
CFRelease( phones );
CFRelease( name );
}

CFRelease( allPeople );
CFRelease( addressBook );

关于iphone - 如何仅获取地址簿中具有传真号码的联系人列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6088577/

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