从地址簿访问kABPersonURLProperty

时间:2013-10-10 06:58:14

标签: ios abaddressbook

我正在尝试访问kABPersonHomePageLabel。根据我的理解,首先我必须访问通过调用此属性生成的字典kABPersonURLProperty,如下所示。 当我在web实例的NSloging时,我得到这个日志:

2013-10-09 20:49:04.823 contacts[1303:907] _$!<HomePage>!$_

ABMultiValueRef websites = ABRecordCopyValue((__bridge ABRecordRef)record, kABPersonURLProperty);
if (ABMultiValueGetCount(websites) > 0) {
    NSLog(@"BBIIGGEERR");
    CFStringRef web = ABMultiValueCopyLabelAtIndex(websites,0);
    NSLog(@"%@",web);
}

我知道我在这个特定的联系人中有一个主页,但我怎样才能提取网址?

1 个答案:

答案 0 :(得分:2)

您必须搜索所有ABMultiValueRef值,例如

更新

    ABMultiValueRef websites = ABRecordCopyValue((__bridge ABRecordRef)record, kABPersonURLProperty);
    NSUInteger i = 0;
    for (i = 0; i < ABMultiValueGetCount(websites); i++)
            {
                NSString *eml = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(websites, i);
                if([eml isEqualToString:(NSString *) kABPersonHomePageLabel]) {
                    NSString *web = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(websites, i);
                    NSLog(@"%@",web);
                }
            }