ABRecordRef检查记录是否仅限Facebook?

时间:2013-04-22 13:10:31

标签: ios abrecord

当循环浏览所有地址簿联系人时,有没有办法查看某条记录是否仅限Facebook?这是在iOS设置中添加Facebook时插入的地址簿记录。

我试图跳过这些记录,只查看用户输入或从其他来源同步的记录。

谢谢

4 个答案:

答案 0 :(得分:3)

使用此snipplet,您可以检测Facebook-Contacts:

+ (BOOL)isPersonFacebookContact:(ABRecordRef)person {
    ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);

    BOOL returnValue = NO;

    if (instantMessage) {
        for (NSInteger i=0 ; i < ABMultiValueGetCount(instantMessage); i++) {
            CFDictionaryRef instantMessageValue = ABMultiValueCopyValueAtIndex(instantMessage, i);
            CFStringRef instantMessageString = CFDictionaryGetValue(instantMessageValue, kABPersonInstantMessageServiceKey);

            if (CFStringCompare(instantMessageString, kABPersonInstantMessageServiceFacebook, 0) == kCFCompareEqualTo) {
                returnValue = YES;
            }

            CFRelease(instantMessageString);
            CFRelease(instantMessageValue);
        }
    }

    CFRelease(instantMessage);

    return returnValue;
}

答案 1 :(得分:0)

每个ABPerson记录只属于一个ABSource

当您遍历所有人员记录时,请在每个记录上调用ABPersonCopySource(person)。 Facebook记录应该都与特定的源记录相关联。我不确定如何识别它:该源记录的kABSourceNameProperty可能包含“Facebook”。

答案 2 :(得分:0)

这似乎对我有用,它不会直接检测到facebook,但你可以进一步评估来源,并且有一个社交档案链接是facebook,以及与facebook联系人的链接联系人然后你会非常肯定那些它的脸书。我用它来获取我可以写回的联系人。用户可以更改其默认联系人创建帐户,但根据我的测试Facebook,只有联系人源永远不会匹配ABAddressBookCopyDefaultSource。

CFArrayRef people = ABAddressBookCopyArrayOfAllPeopleInSource(ab , kABSourceTypeLocal);
AllContacts = CFArrayCreateMutableCopy(kCFAllocatorDefault, CFArrayGetCount(people), people);


// Remove all the contacts that we cant write back to
for (int i = CFArrayGetCount(AllContacts)-1; i >-1  ; i--)
{
    ABRecordRef person = CFArrayGetValueAtIndex(AllContacts, i );
    if((ABPersonCopySource(person) !=ABAddressBookCopyDefaultSource(ab)))
    {
        NSString *fName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
        NSString *lName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));

        DLog(@"Removed a read only contact %@ %@", fName , lName);
        CFArrayRemoveValueAtIndex(AllContacts, i);
    }// else its not something you can write back to, like facebook, twitter.
    CFRelease(person);

}

答案 3 :(得分:0)

  

新版本(没有内存舔):

+ (BOOL)isPersonFacebookContact:(ABRecordRef)person {
    ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);

    BOOL returnValue = NO;

    if (instantMessage) {
        for (NSInteger i = 0; i < ABMultiValueGetCount(instantMessage); i++) {
            CFDictionaryRef instantMessageValue = ABMultiValueCopyValueAtIndex(instantMessage, i);
            CFStringRef instantMessageString = CFDictionaryGetValue(instantMessageValue, kABPersonInstantMessageServiceKey);

            if (instantMessageString) {
                if (CFStringCompare(instantMessageString, kABPersonInstantMessageServiceFacebook, 0) == kCFCompareEqualTo) {
                    returnValue = YES;
                }
            }
            CFRelease(instantMessageValue);
        }

        CFRelease(instantMessage);
    }

    return returnValue; }