//begain lv
for (id *people in peopleArray)
{
// fixed by Wang Yandong
NSString *firstName = (NSString *)ABRecordCopyValue((ABRecordRef)people, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue((ABRecordRef)people, kABPersonLastNameProperty);
NSString *tmpName = [NSString stringWithFormat:@"%@%@",
nil == lastName ? @"" : lastName,
nil == firstName ? @"" : firstName];
int length = [tmpName length];
if(length < 2 || length > 8)
{
[firstName release];
[lastName release];
continue;
}
NSString* cellPhone =nil ;
NSString* workPhone =nil ;
NSString* homeAddress =nil ;
NSString* workAddress =nil;
NSString* homeEmail =nil;
NSString* company =nil;
//cellphone,workphone
ABMultiValueRef mulPhone = (ABMultiValueRef) ABRecordCopyValue(people, kABPersonPhoneProperty) ;
for(CFIndex i=0 ; i < ABMultiValueGetCount(mulPhone) ; i++)
{
NSString* phoneLabel = (NSString*) ABMultiValueCopyLabelAtIndex(mulPhone, i) ;
if([phoneLabel isEqualToString:(NSString*) kABPersonPhoneMobileLabel])
{
cellPhone = (NSString*) ABMultiValueCopyValueAtIndex(mulPhone, i) ;
api_log("homeAddress:%s/n", [cellPhone UTF8String]) ;
}
else if([phoneLabel isEqualToString:(NSString*) kABWorkLabel])
{
workPhone =(NSString*) ABMultiValueCopyValueAtIndex(mulPhone , i) ;
api_log("homeAddress:%s/n", [workPhone UTF8String]) ;
}
}
//homeaddress , workaddress
ABMultiValueRef mulAddress =(ABMultiValueRef) ABRecordCopyValue(people, kABPersonAddressProperty) ;
for(CFIndex i=0 ; i< ABMultiValueGetCount(mulAddress) ; i++)
{
NSString* addressLabel = (NSString*) ABMultiValueCopyLabelAtIndex(mulAddress, i) ;
if([addressLabel isEqualToString:(NSString*)kABHomeLabel ])
{
CFDictionaryRef dict = (CFDictionaryRef)ABMultiValueCopyValueAtIndex(mulAddress, i);
homeAddress = [[NSString alloc ]stringWithFormat:@"%@,%@,%@" ,CFDictionaryGetValue(dict, kABPersonAddressStreetKey) ,
CFDictionaryGetValue(dict, kABPersonAddressCityKey),
CFDictionaryGetValue(dict, kABPersonAddressCountryKey)] ;
api_log("homeAddress:%s/n", [homeAddress UTF8String]) ;
}
else if([addressLabel isEqualToString:(NSString*)kABWorkLabel ])
{
CFDictionaryRef dict = (CFDictionaryRef)ABMultiValueCopyValueAtIndex(mulAddress, i);
workAddress = [[NSString alloc ]stringWithFormat:@"%@,%@,%@" ,CFDictionaryGetValue(dict, kABPersonAddressStreetKey) ,
CFDictionaryGetValue(dict, kABPersonAddressCityKey),
CFDictionaryGetValue(dict, kABPersonAddressCountryKey)] ;
api_log("workAddress:%s/n", [workAddress UTF8String]) ;
}
}
//homeEmail
ABMultiValueRef mulEmail = (ABMultiValueRef)ABRecordCopyValue(people, kABPersonEmailProperty) ;
for(CFIndex i=0 ; i< ABMultiValueGetCount(mulEmail) ; i++)
{
NSString* emailLabel = (NSString*)ABMultiValueCopyLabelAtIndex(mulEmail, i) ;
if([emailLabel isEqualToString:(NSString*)kABHomeLabel])
{
homeEmail = (NSString*) ABMultiValueCopyValueAtIndex(mulEmail, i) ;
api_log("emailLabel:%s ,homeEmail:%s/n", [emailLabel UTF8String] , [homeEmail UTF8String ]) ;
}
}
//company
company = (NSString*)ABRecordCopyValue(people, kABPersonOrganizationProperty);
if(company != nil)
api_log("鍏徃:%s/n", [company UTF8String] ) ;
//"CellPhone", "WorkPhone", "HomeAddress", "Email", "Company", "WorkAddress"
//PLCHAR16 aaa[8] = {'a', 'a', 'a'};
PLCHAR16* core_cellphone = (PLCHAR16 *)[cellPhone cStringUsingEncoding:NSUTF16StringEncoding];
//{'1','3','7','6','1','6','3','5', '9', '4', '1'};
PLCHAR16* core_workphone = (PLCHAR16 *)[workPhone cStringUsingEncoding:NSUTF16StringEncoding];
//{'6','0','5','8','0','8','3','3'};
PLCHAR16* core_homeAddress = (PLCHAR16 *)[homeAddress cStringUsingEncoding:NSUTF16StringEncoding];
//{'a','d','d','r','h','o','m','e'};
PLCHAR16* core_email = (PLCHAR16 *)[homeEmail cStringUsingEncoding:NSUTF16StringEncoding];
//{'a','b','c','@','g','.','c','o', 'm'};
PLCHAR16* core_company = (PLCHAR16 *)[company cStringUsingEncoding:NSUTF16StringEncoding];
//{'c','o','m','p','n','a','m','e'};
PLCHAR16* core_workAddress =(PLCHAR16 *)[workAddress cStringUsingEncoding:NSUTF16StringEncoding];
//{'a','d','d','r','c','o','m','p'};
// PLCHAR16 *vvv[6] = {v1, v2, v3, v4, v5, v6};
PLCHAR16 *property[6] = {core_cellphone, core_workphone, core_homeAddress, core_email, core_company, core_workAddress};
[cellPhone release];
[workPhone release];
[homeAddress release];
[workAddress release];
[homeEmail release];
[company release];
[firstName release];
[lastName release];