2

我正在尝试获取特定 Source 的联系人,但它返回给我 0 对象。

像你一样,看看源是否有组,它将被添加到数组中,但如果没有组,我只需要知道这个源中的联系人数量“例如谷歌,Facebook,..”

for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++)
    {
        ABRecordRef aSource = CFArrayGetValueAtIndex(allSources,i);

        // Fetch all groups included in the current source
        CFArrayRef result = ABAddressBookCopyArrayOfAllGroupsInSource (myAddressBook, aSource);

        // The app displays a source if and only if it contains groups
        if (CFArrayGetCount(result) > 0)
        {
            NSMutableArray *groups = [[NSMutableArray alloc] initWithArray:(NSArray *)result];

            // Fetch the source name
            NSString *sourceName = [self nameForSource:aSource];
            //Create a MySource object that contains the source name and all its groups
            MySource *source = [[MySource alloc] initWithAllGroups:groups name:sourceName];

            // Save the source object into the array
            [list addObject:source];
            [source release];
            [groups release];
        }
        else
        {

            CFArrayRef result= ABAddressBookCopyArrayOfAllPeopleInSource(myAddressBook, aSource);

        }

        CFRelease(result);
    }
4

0 回答 0