从联系方式阅读kABPersonH​​omePageLabel

时间:2014-02-07 16:48:49

标签: ios iphone objective-c abaddressbook abmultivalue

我正在尝试从iPad上的用户联系人访问主页/网站。我实际上是在尝试修改用作Adobe Air原生扩展的现有脚本 - https://github.com/memeller/ContactEditor/blob/master/ContactEditorXCode/ContactEditor.m

我是Objective-C / xCode的新手,所以我真的很努力让这个额外的字段返回...请你帮我一个人。

FREObject homepagesArray = NULL;
FRENewObject((const uint8_t*)"Array", 0, NULL, &homepagesArray, nil);
ABMultiValueRef homepages = ABRecordCopyValue(person, kABPersonHomePageLabel);
if(homepages)
{
    for (CFIndex k=0; k < ABMultiValueGetCount(homepages); k++) {
        NSString* homepage = (__bridge NSString*)ABMultiValueCopyValueAtIndex(homepages, k);
        DLog(@"Adding homepage: %@",homepage);
        FRENewObjectFromUTF8(strlen([homepage UTF8String])+1, (const uint8_t*)[homepage UTF8String], &retStr);
        FRESetArrayElementAt(homepagesArray, k, retStr);
        //[email release];
    }
    CFRelease(homepages);
    FRESetObjectProperty(contact, (const uint8_t*)"homepages", homepagesArray, NULL);
}
else
    FRESetObjectProperty(contact, (const uint8_t*)"homepages", NULL, NULL);
retStr=NULL;

1 个答案:

答案 0 :(得分:0)

您使用错误的标识符来提取ABMultiValueRef homepages。使用kABPersonURLProperty标识符代替kABPersonHomePageLabel,例如

ABMultiValueRef webpages = ABRecordCopyValue(person, kABPersonURLProperty);

// Then iterate thru webpages to get the homepage
for (CFIndex k=0; k < ABMultiValueGetCount(webpages); k++)
{
    // Your code here
}