Iphone 如何在AddressBook框架(iOS 4.2)中确定地址类型
我有一个大问题。。。我计划写一个应用程序来处理用户的地址簿和地址。一切都很好——除了我无法确定addesse的类型是“工作”、“家”还是“其他” 有人知道如何获得家庭、工作和其他方面的标签吗 提前谢谢 鲍里斯 这就是我目前正在使用的功能:Iphone 如何在AddressBook框架(iOS 4.2)中确定地址类型,iphone,objective-c,abaddressbook,Iphone,Objective C,Abaddressbook,我有一个大问题。。。我计划写一个应用程序来处理用户的地址簿和地址。一切都很好——除了我无法确定addesse的类型是“工作”、“家”还是“其他” 有人知道如何获得家庭、工作和其他方面的标签吗 提前谢谢 鲍里斯 这就是我目前正在使用的功能: + (void)testing { //Get the addressbook ABAddressBookRef _addressBookRef = ABAddressBookCreate (); //Fetch all contacts N
+ (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");
}
下面是日志输出:
身份证号码:1
名称:第一个用户
菲尔玛:(空)
地址:{
城市=鲁特林根;
国家=德国;
CountryCode=de;
Street=“some Street”;
ZIP=23456;
}
地址:{
城市=鲁特林根;
国家=德国;
CountryCode=de;
状态=体重;
街道=“街道2号”;
ZIP=98765;
}
身份证号码:2
姓名:第二联系人
菲尔玛:菲尔玛
地址:{
国家=“美国”;
CountryCode=美国;
街道=测试;
}以下是提取通讯簿值的方法:
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);
ABMultiValueRef addresses=ABRecordCopyValue(ref,kabPersonalAddressProperty);
对于(CFIndex j=0;jHi)是否可以转换为swift版本?