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

时间:2013-12-09 03:28:47

标签: ios

我想通过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 个答案:

没有答案