Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve mobile numbers from iPhone Contacts.

I use the following code to set the retrieve the phone number in my app.

CFStringRef addressBookMobile;
ABRecordRef person;
NSString *mobile;

person = CFArrayGetValueAtIndex(people, i);
addressBookMobile = ABRecordCopyValue(person, kABPersonPhoneProperty);
mobile = [NSString stringWithFormat:@"%@", addressBookMobile];

The tag of the contacts is 'mobile'. However, when I use the NSLog(@"%@", mobile); . It displays the <NSCFType: 0x802ffc0>. does any problem for my code?

Should I use the const CFStringRef kABPersonPhoneMobileLabel and how to use? As if I replace it as the above code, it has the error. Can anyone help me? Thank you.

like image 578
Questions Avatar asked Aug 23 '10 10:08

Questions


1 Answers

check the ABPerson Refrence and You need't use @"$!!$" but kABPersonPhoneMobileLabel. the example is:

    ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(person, 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);
    }
like image 153
kzw Avatar answered Oct 04 '22 07:10

kzw