0

我能够ABRecord轻松地检索属性。IE:

NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

但我正在努力寻找一种CFStringRef从记录中检索常量值的方法。例如,我将如何分配NSString人员记录的值kABPersonFatherLabel?(即记录父亲/母亲姓名标签)

感谢您的帮助

4

2 回答 2

0

像这样:

NSString *fatherLabel = (NSString *)kABPersonFatherLabel;

NSString与核心基金会对应的CFStringRef. 有关免费桥接的更多信息,请参阅“免费桥接”。

Core Foundation 框架和 Foundation 框架中有许多可以互换使用的数据类型。这种称为免费桥接的功能意味着您可以使用与 Core Foundation 函数调用的参数或 Objective-C 消息的接收者相同的数据类型。

于 2013-07-15T19:31:31.940 回答
0

没关系,我找到了解决方案。对于其他寻求解决方案的人,请参见下文:

        ABMultiValueRef relatedNames = ABRecordCopyValue(person, kABPersonRelatedNamesProperty);
        NSMutableArray *relatedNameList = [[[NSMutableArray alloc] init] autorelease];
        NSDictionary *dic = [[[NSMutableDictionary alloc] init] autorelease];

        for(CFIndex j = 0; j < ABMultiValueGetCount(relatedNames); j++)
        {
            NSString *relatedNameLabel = [(NSString*)ABMultiValueCopyLabelAtIndex(relatedNames, j) autorelease];
            if ([relatedNameLabel isEqualToString:(NSString *)kABPersonFatherLabel])
            {
                relatedNameString = @"";
            }
            if (relatedNameLabel == nil)
            {
                relatedNameLabel = @"";
            }               
            NSString *relatedNameString = [(NSString*)ABMultiValueCopyValueAtIndex(relatedNames, j) autorelease];
            if (relatedNameString == nil)
            {
                relatedNameString = @"";
            }
            // Add the object to the dictionary
            [dic setValue:(NSString *)relatedNameString forKey:relatedNameLabel];
        }           

You can then access the values from the dictionary by passing the CFStringRef constants (after casting to NSString)

NSString *father = [dic objectForKey:(NSString *)kABPersonFatherLabel];

NSLog( @"%@", father );

于 2013-07-16T11:31:50.920 回答