如何从 ABAddressBookRef 中提取国家/地区字段?
我无法理解如何访问 ABAddressBookRef 中地址的属性。我对电话号码已经做得很好了:
ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
CFRelease(phoneNumberProperty);
但是唉......我不知道如何对地址进行此操作。如果我这样做:
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
我会返回看起来像字典的内容,但它的类型是数组。我如何访问其中的属性?我在网上看到了很多不同的建议,但它们似乎都涉及大约 30 行代码,只是为了从字典中提取一行!
有人可以帮忙吗?谢谢!
I'm having trouble understanding how to access the properties of an address in a an ABAddressBookRef. I've done it okay with telephone numbers:
ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
CFRelease(phoneNumberProperty);
But alas... I can't work out how to do it for addresses. If I do this:
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
I get back what looks like a Dictionary, but it is typed as an Array. How do I access the properties within it? I've seen loads of different suggestions on the web, but they all seem to involve about 30 lines of code, just to pull out one line from a dictionary!
Can anyone help please? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于地址,您将获得一个字典数组,因此您可以循环遍历该数组并从每个字典中提取所需的键值:
您还可以直接循环遍历
ABMultiValueRef
而不是先将其转换为 NSArray :For the addresses, you get an array of dictionaries so you loop through the array and extract the key value you want from each dictionary:
You can also loop directly through the
ABMultiValueRef
instead of converting it to an NSArray first: