如何确定 AddressBook FrameWork 中地址的类型 (iOS 4.2)
我有一个大问题......我计划编写一个处理用户地址簿及其地址的应用程序。一切都很好 - 除了我无法确定地址的类型是“工作”、“家庭”还是“其他”这一事实。
有人知道如何获得家庭、工作和其他的标签吗?
预先感谢
鲍里斯
这是我目前正在使用的功能:
+ (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 =“某条街道”; 邮编=23456; {
地址: 城市=罗伊特林根; 国家=德国; 国家/地区代码 = de; 状态=BW; Street = "街道编号 2"; 邮编=98765; }
ID:2 姓名:第二联系人 菲尔玛: 菲尔玛 地址:{ 国家=“美国”; 国家/地区代码 = 我们; 街道=测试; }
I´ve one big problem... I plan to write an app that deals with the users addressbook and it´s addresses. Everything´s fine - except the fact that I´m not able to determine whether the addesse´s type is "work", "home" or "other".
Does anybody know how to get the label for home, work and other?
Thanks in advance
Boris
This is the function I´m using at the moment:
+ (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");
}
And here´s the log output:
ID: 1
Name: The first user
Firma: (null)
Adresse: {
City = Reutlingen;
Country = Germany;
CountryCode = de;
Street = "some street";
ZIP = 23456;
}
Adresse: {
City = Reutlingen;
Country = Germany;
CountryCode = de;
State = BW;
Street = "Street number 2";
ZIP = 98765;
}
ID: 2
Name: The second contact
Firma: Firma
Adresse: {
Country = "United States";
CountryCode = us;
Street = Test;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是提取地址簿值的方法:
标签类型就是您要查找的类型。
祝你好运
沙尼
here is how you get the address book values extracted:
the label type is what you are looking for.
good luck
shani