在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource [英] Obtaining Specific ABSource from ABAddressBook in iOS 4+

查看:10
本文介绍了在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人举例说明如何在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource?

Does anyone have an example of how to obtain a specific ABSource from the ABAddressBook in iOS 4+?

推荐答案

iOS 4+ 提供了新的 API,允许从 ABAddressBook 中选择特定的 ABSource.这可能对某些操作有用,例如某些来源(例如 Exchange)不支持创建 ABGroup.

iOS 4+ provides new API that allows one to select a specific ABSource from the ABAddressBook. This may be useful as some operations, e.g. creating an ABGroup, are not supported in some sources (i.e. Exchange).

并非所有源类型都支持组,更明显的是,Exchange 对组一无所知."- http://flavors.me/volonbolon#1a5/tumblr

"Not all source types support groups, more conspicuously, Exchange does not know anything about groups." - http://flavors.me/volonbolon#1a5/tumblr

附加的是利用新 API 获取特定类型源的函数,这些源可用于调用 ABGroupCreateInSource().

Attached are functions that leverage the new API to obtain sources of specific types which may be used in calls to ABGroupCreateInSource().

#define CFRELEASE_AND_NIL(x) CFRelease(x); x=nil;
ABRecordRef sourceWithType (ABSourceType mySourceType)
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
    CFIndex sourceCount = CFArrayGetCount(sources);
    ABRecordRef resultSource = NULL;
    for (CFIndex i = 0 ; i < sourceCount; i++) {
        ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
        CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);

        BOOL isMatch = mySourceType == [(NSNumber *)sourceType intValue];
        CFRELEASE_AND_NIL(sourceType);

        if (isMatch) {
            resultSource = currentSource;
            break;
        }
    }

    CFRELEASE_AND_NIL(addressBook);    
    CFRELEASE_AND_NIL(sources);

    return resultSource;
}

ABRecordRef localSource()
{
    return sourceWithType(kABSourceTypeLocal);
}

ABRecordRef exchangeSource()
{
    return sourceWithType(kABSourceTypeExchange);
}

ABRecordRef mobileMeSource()
{
    return sourceWithType(kABSourceTypeMobileMe);
}

这篇关于在 iOS 4+ 中从 ABAddressBook 获取特定的 ABSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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