iOS 6地址簿无法正常工作?

编程入门 行业动态 更新时间:2024-10-20 09:27:00
本文介绍了iOS 6地址簿无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我从地址簿中以编程方式检索电子邮件地址的方法似乎不再适用于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地址簿无法正常工作?

本文发布于:2023-11-01 12:46:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   地址   工作   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!