开发者

Load all the Contacts from iphone PhoneBook in a variable

开发者 https://www.devze.com 2023-02-08 11:03 出处:网络
I am naive to the xcode programming. I need to load all the contacts from the iPhone PhoneBook on a variable.

I am naive to the xcode programming. I need to load all the contacts from the iPhone PhoneBook on a variable.

Could you please suggest me some library or somethin开发者_运维问答g like that. Any sample code would be highly appreciable.

Looking forward to a response.:)

Thanks in advance!!..... :)


Hey all after a long fight I found the following code working

    self.dataSource = [[NSMutableArray alloc]init]; // dataSouce is delared in .h file

ABAddressBookRef addressBook = ABAddressBookCreate(); 
NSMutableArray *allPeople = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); 
int nPeople = ABAddressBookGetPersonCount(addressBook); 

for(int i=0; i < nPeople; i++ ){
    ABRecordRef person = [allPeople objectAtIndex:i];
    NSString *name = @"";
    if(ABRecordCopyValue(person, kABPersonFirstNameProperty) != NULL)
        name = [[NSString stringWithFormat:@"%@", ABRecordCopyValue(person, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    [dataSource addObject: name];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消