gpt4 book ai didi

iphone - 如何确定 AddressBook FrameWork 中地址的类型 (iOS 4.2)

转载 作者:行者123 更新时间:2023-12-03 20:21:13 25 4
gpt4 key购买 nike

我有一个大问题...我计划编写一个应用程序来处理用户的地址簿及其地址。一切都很好 - 除了我无法确定地址的类型是“工作”、“家庭”还是“其他”这一事实。

有人知道如何获得家庭、工作和其他的标签吗?

提前致谢

鲍里斯

这是我目前正在使用的功能:

    + (void)testing {
//Get the addressbook
ABAddressBookRef _addressBookRef = ABAddressBookCreate ();

//Fetch all contacts
NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);

//Walk the contacts
for (id record in allPeople) {
//Get the contact´s id
NSInteger recordId = ABRecordGetRecordID((ABRecordRef)record);

//Get the contact´s name and company
NSString* recordName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
NSString* recordCompany = (NSString *)ABRecordCopyValue((ABRecordRef)record, kABPersonOrganizationProperty);

//Get the contact´s addresses
CFTypeRef adressesReference = ABRecordCopyValue((ABRecordRef)record, kABPersonAddressProperty);
NSArray *adressesArray = (NSArray *)ABMultiValueCopyArrayOfAllValues(adressesReference);
CFRelease(adressesReference);

NSLog(@"ID: %d", recordId);
NSLog(@"Name: %@", recordName);
NSLog(@"Firma: %@", recordCompany);

for (NSString *adress in adressesArray) {
NSLog(@"Adresse: %@", adress);
}

[adressesArray release];
}

CFRelease(_addressBookRef);
[allPeople release];
NSLog(@"\n");
}

这是日志输出:

ID:1姓名:第一个用户菲尔玛:(空)地址:{ 城市=罗伊特林根; 国家=德国; 国家/地区代码 = de; Street =“某条街道”; zip =23456;}

地址:{ 城市=罗伊特林根; 国家=德国; 国家/地区代码 = de; 状态=BW; Street = "街道编号 2"; zip =98765;}

ID:2姓名:第二联系人菲尔玛: 菲尔玛地址:{ 国家=“美国”; 国家/地区代码 = 我们; 街道=测试;}

最佳答案

以下是提取地址簿值的方法:

ABMultiValueRef addresses = ABRecordCopyValue(ref, kABPersonAddressProperty);
for (CFIndex j = 0; j<ABMultiValueGetCount(addresses);j++){
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, j);
CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(addreses, j);
CFStringRef labeltype = ABAddressBookCopyLocalizedLabel(typeTmp);
NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy];
NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy];
NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy];
NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy];
NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy];


[street release];
[city release];
[state release];
[zip release];
[country release];
CFRelease(dict);
CFRelease(type);
CFRelease(typeTmp);
}
CFRelease(addresses);

标签类型就是您要寻找的类型。

祝你好运沙尼

关于iphone - 如何确定 AddressBook FrameWork 中地址的类型 (iOS 4.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4444775/

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