2

在遍历所有通讯录联系人时,是否有办法查看记录是否为 Facebook 专用记录?那是在 iOS 设置中添加 Facebook 时插入的地址簿记录。

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

谢谢

4

4 回答 4

3

使用此 snipplet,您可以检测 Facebook 联系人:

+ (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;
}
于 2013-06-03T09:34:30.103 回答
0

每条ABPerson记录都属于一个ABSource

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

于 2013-04-23T03:07:43.140 回答
0

这似乎对我有用,它不能直接检测到 facebook,但您可以进一步评估来源,是否有一个链接的社交资料是 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);

}
于 2014-02-03T23:28:05.153 回答
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; }
于 2016-08-30T10:43:04.727 回答