地址簿取电话号码问题

时间:2011-11-14 14:56:59

标签: iphone objective-c xcode4

我昨天在10.6上使用xcode 3.2,我使用xcode 4.2升级到10.7在xcode 3.2中运行良好的地址簿项目,在新版本的xcode中不起作用,以下错误是:(/ Users / Blake / Development / g / g / ViewController.m:37:37: {37:37-37:56} {37:48-37:56}:错误:C指针类型'CFStringRef'(又名'const struct) __CFString *')到Objective-C指针类型'NSString *'需要桥接演员[4]

    phones = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef peopleRecords = ABAddressBookCopyArrayOfAllPeople(addressBook);

for (int i = 0; i < CFArrayGetCount(peopleRecords); ++i)
{
    ABRecordRef recordRef = CFArrayGetValueAtIndex(peopleRecords, i);
    ABMultiValueRef phoneRefs = ABRecordCopyValue(recordRef, kABPersonPhoneProperty);

    for (int a = 0; a < ABMultiValueGetCount(phoneRefs); ++a)
    {
        CFStringRef phoneStr = ABMultiValueCopyValueAtIndex(phoneRefs, a);
        NSString* phoneString = (NSString*)phoneStr;
        [phones addObjectphoneString];
        CFRelease(phoneStr);
    }

    CFRelease(phoneRefs);
}

CFRelease(addressBook);
CFRelease(peopleRecords);

for (NSString *phone in phones)
{
    NSLog(@"%@", phone) ;
}

1 个答案:

答案 0 :(得分:0)

我这样做:

//get all phone numbers                   
ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(currentPerson, kABPersonPhoneProperty);
NSArray *phoneNumbersArray = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);

然后我为NSString迭代phoneNumbersArray。