无法在iphone中检索手机通讯录,但对于模拟器工作正常

我想在iPhone上获取联系方式,包括姓名,姓氏,电话号码,电话号码类型,电子邮件地址,电子邮件地址类型等信息 .

我能够为模拟器做这个,但不能用于iPhone

任何人都可以告诉我我错过了什么?

CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
NSLog(@"COUNT : %ld", ABAddressBookGetPersonCount(addressBook));

for(int i = 0; i < numberOfPeople; i++) {

    ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

    NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
    NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
    NSLog(@"Name:%@ %@", firstName, lastName);

    ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);    
}

回答(0)