Search code examples
iosaddressbook

fetching number from addressbook issue


i am using following code for this purpose

 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]; 
        }   

now my problem is that nslog of _phonearray is like this

_

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

but i want like

_Phonearray(
    "6589326593",
    "6544989878"
)

so what chances should i do in code:?


Solution

  • So, you want to remove all non-number characters from mobile? I found a method here:

    Removing all non wanted characters using the NSCharacterSet - Stack Overflow

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