ABAddressBook ABSource和ABSourceType [英] ABAddressBook ABSource and ABSourceType

查看:200
本文介绍了ABAddressBook ABSource和ABSourceType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可用于搜索Exchange GAL的应用程序,但是,我发现有关此主题的新4.0文档令人困惑。有谁知道如何在GAL中搜索包含特定字符串的名称(例如Smi)?我的源代码目前几乎无用,因为我只是试图指出我只想要搜索GAL而不是设备上的本地联系人。另外,如何使用kABSourceTypeSearchableMask?我在这里缺少一些基本的东西。来自文档......

I am attempting to create an app that can be used to search an Exchange GAL, however, I am finding the new 4.0 documentation regarding this subject confusing. Does anyone know how I might go about searching the GAL for names containing a specific string (e.g. "Smi")? My source code at the moment is all but useless as I am simply trying to wrap my head around how to specify that I am wanting only to search the GAL and not the local contacts on the device. Also, how is kABSourceTypeSearchableMask used? I am missing something fundamental here. From the documentation...

源类型

这些常量标识源的类型。

These constants identify the type of a source.

enum {
    kABSourceTypeLocal       = 0x0,
    kABSourceTypeExchange    = 0x1,
    kABSourceTypeExchangeGAL = kABSourceTypeExchange | kABSourceTypeSearchableMask,
    kABSourceTypeMobileMe    = 0x2,
    kABSourceTypeLDAP        = 0x3 | kABSourceTypeSearchableMask,
    kABSourceTypeCardDAV     = 0x4,
    kABSourceTypeCardDAVSearch = kABSourceTypeCardDAV | kABSourceTypeSearchableMask,
};
typedef int ABSourceType;

当我查询默认的源类型时,我会得到1,这似乎表示默认类型是kABSourceTypeExchange,这是正确的,因为这是我在我的设置中。我不知道如何超越这一点......

When I query for the default source type, I do get "1" which would appear to indicate that the default type is "kABSourceTypeExchange" which would be correct as this is what I have in my Settings. I do not know how to proceed beyond this point...

由于整个源概念是4.0中ABAddressBook框架的新概念,我不认为人们有很多经验,但希望有人可以帮助我理解如何使用上述...谢谢。

As the whole source concept is a new to the ABAddressBook framework in 4.0 I don't imagine that folks have much experience with this, but hoping someone might help me understand how to work with the above...thanks.

推荐答案

获取访问Exchange GAL,您需要使用函数ABAddressBookCopyArrayOfAllSources来获取所有源的数组,然后遍历数组以尝试获取Exchange GAL的正确源。使用ABRecordCopyValue()函数获取源的kABSourceTypeProperty属性。

To get access to the Exchange GAL, you'll need to use the function ABAddressBookCopyArrayOfAllSources to get an array of all sources, and then iterate over the array to try and get the correct source for the Exchange GAL. Use the ABRecordCopyValue() function to get the kABSourceTypeProperty property of the source.

例如

ABRecordRef searchableExchangeSource;

addressBook = ABAddressBookCreate();
CFArrayRef allSources = ABAddressBookCopyArrayOfAllSources(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++) {
    ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(allSources, i);

    // Get source properties
    NSNumber *sourceTypeRef = (NSNumber *)((CFNumberRef)ABRecordCopyValue(source, kABSourceTypeProperty));
    NSString *sourceTypeName = (NSString *)((CFStringRef)ABRecordCopyValue(source, kABSourceNameProperty));
    int sourceType = [sourceTypeRef intValue];
    NSLog(@"Found Source Type: %@ with ABSourceType %i", sourceTypeName,sourceType);
    if (sourceType == kABSourceTypeExchangeGAL) {
        searchableExchangeSource = source;
    }
    [sourceTypeRef release];
    [sourceTypeName release];
}

请注意,如果您设置了多个Exchange帐户,您将获得多个来源使用相同的ABSourceType。不幸的是,在我的有限测试中,Exchange GAL的kABSourceTypeNameProperty为NULL,因此您无法使用此属性来区分多个Exchange GAL源。

Note if you have multiple "Exchange" accounts set up you will get multiple sources with the same ABSourceType. Unfortunately from my limited testing, the kABSourceTypeNameProperty for Exchange GALs is NULL so you can't use this property to differentiate between multiple Exchange GAL sources.

获得适当的源后,它是ABRecordRef类型,所以你可以像任何其他记录一样与它进行交互。

Once you have the appropriate source, it is of the type ABRecordRef so you can interact with it just like any other record.

这篇关于ABAddressBook ABSource和ABSourceType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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