如何在iOS 6中正确使用ABAddressBookCreateWithOptions方法? [英] How do I correctly use ABAddressBookCreateWithOptions method in iOS 6?

查看:276
本文介绍了如何在iOS 6中正确使用ABAddressBookCreateWithOptions方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解iOS 6中的 ABAdressBookCreateWithOptions ABAddressBookRequestAccessWithCompletion 方法。

I am trying to understand the ABAdressBookCreateWithOptions and ABAddressBookRequestAccessWithCompletion methods in iOS 6.

我已经找到的大多数信息如下,要请求访问联系人数据,调用 ABAddressBookRequestAccessWithCompletion code> ABAddressBookCreateWithOptions function。

The most information i have been able to find is the following, "To request access to contact data, call the ABAddressBookRequestAccessWithCompletion function after calling the ABAddressBookCreateWithOptions function."

我相信这些方法应该提醒用户决定是否允许应用程序访问联系人,但是当我使用它们时,我没有看到任何提示。

I believe together these methods should alert the user to decide whether to allow the application access to contacts, however when I use them I am seeing no prompt.

有人可能提供一些示例代码,如何在现实世界的示例中一起调用这些方法?如何创建( CFDictionary )选项?我有工作代码使用已弃用的 ABAddressBookCreate 方法,但需要更新到iOS 6以适应隐私问题。

Could someone provide some sample code of how these methods should be called together in a real world example? How do I create (CFDictionary) options? I have working code using the deprecated ABAddressBookCreate method, but need to update to iOS 6 to accommodate privacy concerns.

先感谢任何可以在这里散发光芒的人。

Thanks in advance to anyone who can shed some light here!

推荐答案

现在NDA已经解除了,这里是我的解决方案为你需要替换一个方法返回一个数组。 (如果您不想在用户决定时阻止,并准备好可能重写一些现有代码,请参阅下面的David的解决方案):

Now that the NDA has been lifted, here is my solution for this for the where you need replace a method which returns an Array. (If you'd rather not block while the user is deciding and are ready to potentially rewrite some of your existing code, please look at David's solution below):

ABAddressBookRef addressBook = ABAddressBookCreate();

__block BOOL accessGranted = NO;

if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);

    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });

    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);    
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}


if (accessGranted) {

    NSArray *thePeople = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
    // Do whatever you need with thePeople...

}

希望这有助于某人...

Hope this helps somebody...

这篇关于如何在iOS 6中正确使用ABAddressBookCreateWithOptions方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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