我从地址簿中以编程方式检索电子邮件地址的方法似乎不再适用于iOS 6设备。它在iOS 5中工作,奇怪的是,仍然适用于iOS 6模拟器。是否有一种以编程方式从用户的地址簿中检索联系人的新方法?
My method of programmatically retrieving e-mail addresses from the Address Book no longer seems to work on iOS 6 devices. It worked in iOS 5 and oddly, still works in the iOS 6 Simulator. Is there a new way to programmatically retrieve contacts from a users' Address Book?
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); self.contacts = [[NSMutableArray alloc] init]; int contactIndex = 0; for (int i = 0; i < nPeople; i++) { // Get the next address book record. ABRecordRef record = CFArrayGetValueAtIndex(allPeople, i); // Get array of email addresses from address book record. ABMultiValueRef emailMultiValue = ABRecordCopyValue(record, kABPersonEmailProperty); NSArray *emailArray = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(emailMultiValue); [self.contacts addObject:emailArray]; }为了澄清,上面没有崩溃,它只是没有返回任何结果。 ABAddressBookCopyArrayOfAllPeople为空。谢谢!
To clarify, the above does not crash, it simply returns no results. ABAddressBookCopyArrayOfAllPeople is empty. Thanks!
推荐答案可能与新的隐私控制相关 - 从iOS 6开始,在设备上,应用无法访问未经用户许可,用户的联系人。从文档:
Probably related to the new privacy controls—as of iOS 6, on the device, an app can’t access the user’s contacts without their permission. From the documentation:
在iOS 6.0及更高版本中,如果调用者无权访问通讯簿数据库:
On iOS 6.0 and later, if the caller does not have access to the Address Book database:
•对于针对iOS 6.0及更高版本链接的应用,此函数返回NULL。
• For apps linked against iOS 6.0 and later, this function returns NULL.
•对于与之前链接的应用在iOS版本中,此函数返回一个空的只读数据库。
• For apps linked against previous version of iOS, this function returns an empty read-only database.
如果您还没有看到权限警报出现( SomeApp希望访问您的联系人),直接地址簿API可能只是假设他们没有访问权限而且默默地失败;您可能必须显示来自AddressBookUI框架的内容才能触发它。
If you haven’t seen the permissions alert come up ("SomeApp would like access to your contacts"), it’s possible that the direct address-book APIs just assume that they don’t have access and silently fail; you might have to display something from the AddressBookUI framework to trigger it.
更多推荐
iOS 6地址簿无法正常工作?
发布评论