嗨,我在我的應用程序中使用地址簿。我在模擬器中獲取聯繫人。但在iPhone 4S中,它不顯示設備中的任何聯繫人。而在iPhone 4中,我只有1個聯繫人。我不明白爲什麼它不顯示所有聯繫人。我正在使用以下代碼。請幫幫我。iphone中獲取聯繫人信息的問題
ABAddressBookRef ab=ABAddressBookCreate();
NSArray *arrTemp=(NSArray *)ABAddressBookCopyArrayOfAllPeople(ab);
UIImage* image;
ContactArray=[[NSMutableArray alloc] init];
for (int i=0;i<[arrTemp count];i++)
{
NSMutableDictionary *dicContact=[[NSMutableDictionary alloc] init];
NSString *str=(NSString *) ABRecordCopyValue([arrTemp objectAtIndex:i], kABPersonFirstNameProperty);
UIImage *imgContactImage=(UIImage *)ABPersonCopyImageDataWithFormat([arrTemp objectAtIndex:i],kABPersonImageFormatOriginalSize);
if(ABPersonHasImageData([arrTemp objectAtIndex:i])){
image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData([arrTemp objectAtIndex:i])];
} else {
image = [UIImage imageNamed:@""];
}
NSString* [email protected]"";
NSString *[email protected]"";
//Get mobile phone number
ABMultiValueRef phoneNumbers = (ABMultiValueRef)ABRecordCopyValue([arrTemp objectAtIndex:i], kABPersonPhoneProperty);
CFRelease(phoneNumbers);
if(ABMultiValueGetCount(phoneNumbers)>0) {
for(CFIndex j = 0; j < ABMultiValueGetCount(phoneNumbers); j++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phoneNumbers, j);
if([mobileLabel isEqualToString:@"_$!<Mobile>!$_"]) {
phoneNumber = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, j);
}
}
}
else
{
[email protected]"";
}
NSLog(@"%@",phoneNumber);
}
試試這些代碼http://stackoverflow.com/questions/4883248/load-all-the-contacts-from-iphone-phonebook-in-a-variable和http://zcentric.com/2008/09/ 19/access-the-address-book /希望這會有所幫助.. –