0

如何从ios中的通讯录中仅获取移动部分记录?

我只想将一条记录添加到我的数组中,该记录是从移动部分记录中获取的。

我怎么做。我正在获取所有电话财产记录。但我只需要获取移动部分记录。

NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook);
NSLog(@"allpeople%@", allPeople);

for (id record in allPeople) {
    CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
    NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);

    NSLog(@"phones %@",phones);

    CFRelease(phoneProperty);
    NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init];
    NSMutableString *newPhone = [[NSMutableString alloc] init];

    for (NSString *phone in phones) {
        if(![newPhone isEqualToString:@""])
            [newPhone appendString:@", "];
        [newPhone appendString:phone];
    }
4

1 回答 1

0

你可以试试这样的..

ABMultiValueRef phoneNumbers = ABRecordCopyValue(abPerson, kABPersonPhoneProperty);
    if (phoneNumbers) {
        CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
        for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
            NSString *phone = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumbers, i);
            CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
            if (label) {
                if (CFEqual(label, kABPersonPhoneMobileLabel)) {
                    primaryPhoneText.text = phone;
                } else {
                }
                CFRelease(label);
                [allPhones addObject:phone]; // allPhones is an array here.
            }
        }
        CFRelease(phoneNumbers);
    }

希望这会帮助你..

享受编码..

于 2013-08-19T12:08:23.230 回答