如何从阵列中删除facebook联系人? Ios地址簿

问题描述 投票:0回答:1

我正在使用地址簿,但不希望他带来facebook的联系方式。我做了一个if语句来过滤,但我没有从我的数组中删除它。

ABMultiValueRef emails  = ABRecordCopyValue(person, kABPersonEmailProperty);

    CFIndex numberOfEmails = ABMultiValueGetCount(emails);
    userDetail.allEmails = [@[] mutableCopy];
    for (CFIndex i = 0; i < numberOfEmails; i++) {

        NSString *email = CFBridgingRelease(ABMultiValueCopyValueAtIndex(emails, i));

        if ([email containsString:@"@facebook.com"]) {
            NSLog(@"remove emails: %@", userDetail.allEmails);

        }
        [userDetail.allEmails addObject:email];
    }
ios nsmutablearray nsarray addressbook
1个回答
0
投票

我使用NSPredicateNSCompoundPredicate进行过滤。

 CFErrorRef *error = NULL;
        ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
        CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
        CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
        NSMutableArray *mylist = [[NSMutableArray alloc] initWithCapacity:numberOfPeople];
        for(int i = 0; i < numberOfPeople; i++) {
            ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
            NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
            NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
            ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
            for (CFIndex i = 0; i < ABMultiValueGetCount(email); i++) {
                NSString *emailId = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(email, i);
                NSDictionary *myObjlist = @{@"email":emailId,@"name":[NSString stringWithFormat:@"%@ %@",firstName,lastName]};
                //NSLog(@"Name:%@ %@ : %@", firstName, lastName,myObjlist);
                [mylist addObject:myObjlist];

            }
        }
        //NSLog(@"mylist : %@",mylist);
        NSPredicate *p = [NSPredicate predicateWithFormat:
            @"SELF['email'] CONTAINS '@facebook.com'"];
        NSPredicate *notFilter = [NSCompoundPredicate notPredicateWithSubpredicate:p];
        NSArray *res = [mylist filteredArrayUsingPredicate:notFilter];
        NSLog(@"awesome %@", res);

如果您有任何疑问,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.