从地址簿中仅获取移动部分记录(不是来自iphone,家庭标签等)?

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

如何从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];
    }
iphone ios ios5 ios6 ios4
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);
    }

希望这会帮助你...

享受编码..

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