从地址簿问题中获取号码

时间:2013-04-01 13:42:54

标签: ios addressbook

我正在为此目的使用以下代码

 ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(ref, kABPersonPhoneProperty);
        NSString* mobile=@"";
        NSString* mobileLabel;
        for (int i=0; i < ABMultiValueGetCount(phones); i++) {
            //NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
            //NSLog(@"%@", phone);
            mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
            if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
                NSLog(@"mobile:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
                NSLog(@"iphone:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
                NSLog(@"pager:");
            }
            [mobile release];
            mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
            NSLog(@"%@", mobile);
            [_Phonearray addObject:mobile]; 
        }   

现在我的问题是_phonearray的nslog就像这样

_

Phonearray(
    "(658) 932-6593",
    "(654) 498-9878"
)

但我想要

_Phonearray(
    "6589326593",
    "6544989878"
)

那么我应该在代码中做些什么:?

1 个答案:

答案 0 :(得分:1)

那么,您想要从mobile中删除所有非数字字符吗?我在这里找到了一种方法:

Removing all non wanted characters using the NSCharacterSet - Stack Overflow

NSCharacterSet* charactersToRemove = [[NSCharacterSet decimalDigitCharacterSet] invertedSet] ;
mobile = [[mobile componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""] ;