iOS 6地址簿无法正常工作? [英] iOS 6 Address Book not working?

查看:103
本文介绍了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地址簿无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆