0

这段代码有什么问题:

NSMutableArray* contactArray = [[NSMutableArray alloc] init];

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); // Over here it returns zero count.
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i = 0 ; i < nPeople; i++) {
    NSMutableDictionary* dicContact = [[[NSMutableDictionary alloc] init] autorelease];
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
}

它在模拟器中完美运行,但无法获取设备中的联系人列表。我错过了从设备获取联系人的地方?

控制台输出:(模拟器)

Printing description of contactArray:

    <__NSArrayM 0xa13e810>(
{
    City = "";
    State = "";
    Street = "";
    ZIP = "";
    email = "kate-bell@mac.com";
    firstname = Kate;
    lastname = Bell;
    organization = "Creative Consulting";
    telephone = "(555) 564-8583";
}
)
4

0 回答 0