开发者

iPhone ABAddressBookRef. Retrieve all data

I worked with AddressBook framework (iPhone SDK). I displayed my contacts as modal view controller and browsed it. I wonder is it possible to retrieve all contacts data without this mod开发者_开发百科al view controller and human interactions.

P.S. it seems NOT because of Apple policy, but I still need to have a '100% sure' answer


To retrieve an array of all contacts use the ABAddressBookCopyArrayOfAllPeople function as the following :

- (void)viewDidLoad
{
    [super viewDidLoad];
    ABAddressBookRef addressBook = ABAddressBookCreate();
    if (addressBook != nil)
    {
        NSLog(@"Successfully accessed the address book.");
        CFArrayRef arrayOfAllPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
        if (arrayOfAllPeople != nil)
        {
            NSUInteger peopleCounter=0;
            for (peopleCounter=0;peopleCounter<CFArrayGetCount(arrayOfAllPeople); peopleCounter++)
            {
                ABRecordRef thisPerson=CFArrayGetValueAtIndex(arrayOfAllPeople,peopleCounter);
                NSLog(@"%@", thisPerson);
                /* Use the [thisPerson] address book record */
            }
            CFRelease(arrayOfAllPeople);
        }
        /* if (allPeople != nil){ */
        CFRelease(addressBook);
    } /* if (addressBook != nil){ */
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜