无需 GUI 即可获取 iPhone 地址簿内容
我想列出地址簿中人员的所有电话号码(或任何其他字段)。
我编写了以下代码:
- (void)addressBookFill{
ABAddressBookRef addressBook = ABAddressBookCreate();
people = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
[addressBook release];
}
- (void)printAddressBook{
for(id person in people){
NSLog(@"%@", [person class]);
NSLog(@"\t%@", person );
}
}
当我调用 printAddressBook 方法时,我在控制台上看到以下内容:
2010-07-06 10:34:11.998 app[91420:207] __NSCFType
2010-07-06 10:34:11.999 app[91420:207] <CPRecord: 0x5d56ce0 ABPerson>
我不知道如何取消引用此 ABPerson 对象,如何从中获取任何信息。
我尝试过:
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
但我遇到了一些例外。
有人能告诉我如何从这些对象中获取一些信息吗?
I would like to list all phone numbers (or any other field) of people in the addressbook.
I've written the following code:
- (void)addressBookFill{
ABAddressBookRef addressBook = ABAddressBookCreate();
people = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
[addressBook release];
}
- (void)printAddressBook{
for(id person in people){
NSLog(@"%@", [person class]);
NSLog(@"\t%@", person );
}
}
When I invoke the printAddressBook method I get this on my console:
2010-07-06 10:34:11.998 app[91420:207] __NSCFType
2010-07-06 10:34:11.999 app[91420:207] <CPRecord: 0x5d56ce0 ABPerson>
And I don't have any idea, how to dereference this ABPerson object, how to get any info from it.
I tried:
firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
but I got some exceptions.
Can anybody tell me how to get some info from these objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读有关 ABPerson 类的文档:
http://开发人员。 apple.com/mac/library/documentation/UserExperience/Reference/AddressBook/Classes/ABPerson_Class/Reference/Reference.html
以及 ABRecord 类:
http://developer.apple.com/mac /library/documentation/UserExperience/Reference/AddressBook/Classes/ABRecord_Class/Reference/Reference.html#//apple_ref/occ/cl/ABRecord
您可以通过以下方式获取可用属性:
[ 编辑]
iPhone 上,您可以使用以下代码来访问值:
Read the documentation about the ABPerson class:
http://developer.apple.com/mac/library/documentation/UserExperience/Reference/AddressBook/Classes/ABPerson_Class/Reference/Reference.html
and also the ABRecord class:
http://developer.apple.com/mac/library/documentation/UserExperience/Reference/AddressBook/Classes/ABRecord_Class/Reference/Reference.html#//apple_ref/occ/cl/ABRecord
You can get the available properties with:
[ EDIT ]
On iPhone, you can use the following code to access a value:
也许这个代码对你的iOS5有帮助,请喜欢它
May be this code will help you for iOS5, please like it
您只想获取那些在我的联系人上有电子邮件的联系人,因此请在 iOS5 上使用此代码,
如果它有效,请喜欢它。
首先添加
AddressBook.framework
和#import
You want get only those contact who has email on my contact so use this code for iOS5
Please like it if it work
First add
AddressBook.framework
and#import <AddressBook/AddressBook.h>