0

我正在从事需要从联系人中获取单个人的所有信息的项目。

我可以使用此代码获取所有电话、电子邮件或其他属性

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);

for(CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) {

    NSLog(@"Phone number is here >>>>>>%@",(NSString*)ABMultiValueCopyValueAtIndex(multi, i));
}

}

但是我需要为所有属性编写这段代码。而且您知道有很多字段,例如昵称,生日等。

那么,有什么方法可以让我获得单身人士的所有属性吗?

4

2 回答 2

1
 CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(multi, i);
                    NSString *displayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                    displayName=[displayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];

                    if ([displayName isEqualToString:@"Home"]) 
                    {
                        propertyIndexUser=imIndex_HomeUser;
                        propertyIndexService=imIndex_HomeService;
                        imIndex_HomeUser+=2;
                        imIndex_HomeService+=2;
                    }
                    else if ([displayName isEqualToString:@"Work"]) 
                    {
                        propertyIndexUser=imIndex_WorkUser;
                        propertyIndexService=imIndex_WorkService;
                        imIndex_WorkUser+=2;
                        imIndex_WorkService+=2;
                    }
                    else
                    {
                        propertyIndexUser=imIndex_OtherUser;
                        propertyIndexService=imIndex_OtherService;
                        imIndex_OtherUser+=2;
                        imIndex_OtherService+=2;
                    }

                    ContactProperty* objIMContactProperty;

                    objIMContactProperty=[[ContactProperty alloc] init];
                    if (displayName==nil) {
                        displayName = @"Other";
                    }
                    objIMContactProperty.mDisplayName= [NSString stringWithString:displayName];
                    objIMContactProperty.mContactPropertyString=(NSString*)CFDictionaryGetValue(dict, @"username");
                    objIMContactProperty.mContactPropId=propertyIndexUser;
                    objIMContactProperty.mContactDataType=@"Text";
                    [objPhoneContact.mPropertyArray addObject:objIMContactProperty];
                    [objIMContactProperty release];

                    objIMContactProperty=[[ContactProperty alloc] init];

                    objIMContactProperty.mDisplayName= [NSString stringWithString:displayName];
                    objIMContactProperty.mContactPropertyString=(NSString*)CFDictionaryGetValue(dict, @"service");
                    objIMContactProperty.mContactPropId=propertyIndexService;
                    objIMContactProperty.mContactDataType=@"Text";
                    [objPhoneContact.mPropertyArray addObject:objIMContactProperty];
                    [objIMContactProperty release];

                    if(dict)
                        CFRelease(dict);
                }
            }
            //CFRelease(dict);
            if(multi)
                CFRelease(multi);



            multi=ABRecordCopyValue(record,kABPersonURLProperty);

            NSUInteger urlIndex_home_page=501;
            NSUInteger urlIndex_home=521;
            NSUInteger urlIndex_work=541;
            NSUInteger urlIndex_other=561;  //~600



            multiCount=ABMultiValueGetCount(multi);
            if(multiCount ==0)
            {
                //objPhoneContact.mWebUrl=@"";
            }
            else 
            {
                for( int i=0; i < multiCount; i++)
                {


                    ContactProperty* objUrlContactProperty=[[ContactProperty alloc] init];

                    objUrlContactProperty.mContactPropertyString=(NSString*)ABMultiValueCopyValueAtIndex(multi, i);
                    objUrlContactProperty.mDisplayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                    objUrlContactProperty.mDisplayName = [objUrlContactProperty.mDisplayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];

                    if([objUrlContactProperty.mDisplayName caseInsensitiveCompare:@"HomePage"]==NSOrderedSame)
                    {
                        objUrlContactProperty.mContactPropId=urlIndex_home_page;
                        urlIndex_home_page++;
                    }
                    else if([objUrlContactProperty.mDisplayName caseInsensitiveCompare:@"home"]==NSOrderedSame)
                    {
                        objUrlContactProperty.mContactPropId=urlIndex_home;
                        urlIndex_home++;
                    }
                    else if([objUrlContactProperty.mDisplayName caseInsensitiveCompare:@"work"]==NSOrderedSame)
                    {
                        objUrlContactProperty.mContactPropId=urlIndex_work;
                        urlIndex_work++;
                    }

                    else 
                    {
                        objUrlContactProperty.mContactPropId=urlIndex_other;
                        urlIndex_other++;
                    }

                    objUrlContactProperty.mContactDataType=@"Url";

                    [objPhoneContact.mPropertyArray addObject:objUrlContactProperty];
                    [objUrlContactProperty release];
                }
            }

            if(multi)
                CFRelease(multi);



            multi = ABRecordCopyValue(record, kABPersonAddressProperty);

            NSUInteger addressIndex_home=701;
            NSUInteger addressIndex_work=901;
            NSUInteger addressIndex_other=1101;  //~1300


            multiCount=ABMultiValueGetCount(multi);
            if(multiCount ==0)
            {
                //objPhoneContact.mWebUrl=@"";
            }
            else 
            {


                for( int i=0; i < multiCount; i++)
                {
                    CFTypeRef adressDictionaryRef=ABMultiValueCopyValueAtIndex(multi, i);

                    NSDictionary* addressDictionary=(NSDictionary*)adressDictionaryRef;
                    NSString* street=[addressDictionary objectForKey:(NSString*)kABPersonAddressStreetKey];
                    NSString* city=[addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey];
                    NSString* state=[addressDictionary objectForKey:(NSString*)kABPersonAddressStateKey];
                    NSString* zip=[addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
                    NSString* country=[addressDictionary objectForKey:(NSString*)kABPersonAddressCountryKey];
            //      NSString* countryCode=[addressDictionary objectForKey:(NSString*)kABPersonAddressCountryCodeKey];

                    //objAddressContactProperty.mContactPropertyString=[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",street,city,state,zip,country,countryCode];

                    NSMutableString *displayName;
                    displayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                    displayName = [displayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];

                    DLog(@"Address Property: %@",displayName);

                    int propertyIndex=0;

                    if([displayName caseInsensitiveCompare:@"home"]==NSOrderedSame)
                    {
                        propertyIndex=addressIndex_home;
                        addressIndex_home+=10;
                    }

                    else if([displayName caseInsensitiveCompare:@"work"]==NSOrderedSame)
                    {
                        propertyIndex=addressIndex_work;
                        addressIndex_work+=10;
                    }
                    else 
                    {
                        propertyIndex=addressIndex_other;
                        addressIndex_other+=10;
                    }



                    ContactProperty* objAddressContactProperty;

                    if (street!=nil) 
                    {
                        objAddressContactProperty=[[ContactProperty alloc] init];
                        objAddressContactProperty.mDisplayName=displayName;
                        objAddressContactProperty.mContactPropId=propertyIndex;
                        objAddressContactProperty.mContactDataType=@"Text";
                        objAddressContactProperty.mContactPropertyString=street;
                        [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
                        [objAddressContactProperty release];
                    }

                    propertyIndex++;

                    if (city!=nil) 
                    {
                        objAddressContactProperty=[[ContactProperty alloc] init];
                        objAddressContactProperty.mDisplayName=displayName;
                        objAddressContactProperty.mContactPropId=propertyIndex;
                        objAddressContactProperty.mContactDataType=@"Text";
                        objAddressContactProperty.mContactPropertyString=city;
                        [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
                        [objAddressContactProperty release];
                    }

                    propertyIndex++;

                    if (state!=nil) 
                    {
                        objAddressContactProperty=[[ContactProperty alloc] init];
                        objAddressContactProperty.mDisplayName=displayName;
                        objAddressContactProperty.mContactPropId=propertyIndex;
                        objAddressContactProperty.mContactDataType=@"Text";
                        objAddressContactProperty.mContactPropertyString=state;
                        [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
                        [objAddressContactProperty release];
                    }

                    propertyIndex++;

                    if (zip!=nil) 
                    {
                        objAddressContactProperty=[[ContactProperty alloc] init];
                        objAddressContactProperty.mDisplayName=displayName;
                        objAddressContactProperty.mContactPropId=propertyIndex;
                        objAddressContactProperty.mContactDataType=@"Text";
                        objAddressContactProperty.mContactPropertyString=zip;
                        [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
                        [objAddressContactProperty release];
                    }

                    propertyIndex++;

                    if (country!=nil) 
                    {
                        objAddressContactProperty=[[ContactProperty alloc] init];
                        objAddressContactProperty.mDisplayName=displayName;
                        objAddressContactProperty.mContactPropId=propertyIndex;
                        objAddressContactProperty.mContactDataType=@"Text";
                        objAddressContactProperty.mContactPropertyString=country;
                        [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
                        [objAddressContactProperty release];
                    }

                    if(adressDictionaryRef)
                        CFRelease(adressDictionaryRef);
                }
            }






            if(multi)
                CFRelease(multi);

            [tempArray addObject:objPhoneContact];
            [objPhoneContact release];

            if(shouldReleasePool)
            {
                [innerPool drain];
                shouldReleasePool=NO;
            }

        }
        self.mPhoneContactArray=tempArray;
        CFRelease(iPhoneAddressBook);
        CFRelease(allPeople);


        [pool drain];


        return [tempArray autorelease];
    }
于 2012-05-08T06:02:35.733 回答
0

不,您必须对所有属性执行此操作,除此之外别无他法。然而,这里是所有这些获取细节的代码。这里可能有一些额外的东西,因为我是为我的应用程序做的。不一般。这里的联系人是我自己的对象,其中包含名称、公司和包含属性的属性数组等数据。这不是完美的代码,只是为了展示 ua 模型,分为两部分:

-(NSMutableArray*)getPhoneContacts
{

    NSLog(@"getPhoneContacts");

    NSAutoreleasePool *pool= [[NSAutoreleasePool alloc] init];

    NSMutableArray *tempArray=[[NSMutableArray alloc] init];
    ABAddressBookRef iPhoneAddressBook=ABAddressBookCreate();
    if(!iPhoneAddressBook)
    {
        DLog(@"unable to open addressBook");
    }
    for(i=0;i<[peopleArray count];i++)
    {



        if((i&255)==0)
        {
            innerPool= [[NSAutoreleasePool alloc] init];
            shouldReleasePool=YES;
        }


        ABRecordRef record=[peopleArray objectAtIndex:i];

        Contact *objPhoneContact=[[Contact alloc] init];
        objPhoneContact.contactType=STATIC_CONTACT;

        int32_t uniqueId=ABRecordGetRecordID(record);


        objPhoneContact.addressBookId=uniqueId;



        CFStringRef temp;


        temp=ABRecordCopyValue(record, kABPersonPrefixProperty);
        if (temp) {
            objPhoneContact.mPrefixName=[NSString stringWithString:(NSString*)temp];
            CFRelease(temp);
        }

        temp=ABRecordCopyValue(record, kABPersonMiddleNameProperty);
        if (temp) {
            objPhoneContact.mMiddleName=[NSString stringWithString:(NSString*)temp];
            CFRelease(temp);
        }

        temp=ABRecordCopyValue(record, kABPersonNicknameProperty);
        if (temp) {
            objPhoneContact.mNickName=[NSString stringWithString:(NSString*)temp];
            CFRelease(temp);
        }

        temp=ABRecordCopyValue(record, kABPersonSuffixProperty);
        if (temp) {
            objPhoneContact.mSuffixName=[NSString stringWithString:(NSString*)temp];
            CFRelease(temp);
        }

        ContactProperty* objAddressContactProperty;
        int propertyIndex=0;

        temp=ABRecordCopyValue(record, kABPersonFirstNamePhoneticProperty);
        if (temp) {

            propertyIndex=4;

            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"PhoneticFirstName";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Text";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithString:(NSString*)temp];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            CFRelease(temp);
        }

        temp=ABRecordCopyValue(record, kABPersonLastNamePhoneticProperty);
        if (temp) {

            propertyIndex=5;

            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"PhoneticLastName";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Text";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithString:(NSString*)temp];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            CFRelease(temp);
        }


        temp=ABRecordCopyValue(record, kABPersonJobTitleProperty);
        if (temp) {

            propertyIndex=6;

            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"JobTitle";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Text";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithString:(NSString*)temp];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            CFRelease(temp);
        }

        temp=ABRecordCopyValue(record, kABPersonDepartmentProperty);
        if (temp) {

            propertyIndex=7;

            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"Department";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Text";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithString:(NSString*)temp];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            CFRelease(temp);
        }
        NSDate *tempDate=nil;


        tempDate=(NSDate*)ABRecordCopyValue(record, kABPersonBirthdayProperty);
        if (tempDate) {

            propertyIndex=1401;

            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"BirthDay";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Date";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithFormat:@"%@",tempDate];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            [tempDate release];
           // CFRelease(temp);
        }


        temp=ABRecordCopyValue(record, kABPersonNoteProperty);
        if (temp) {

            propertyIndex=1901;


            objAddressContactProperty=[[ContactProperty alloc] init];
            objAddressContactProperty.mDisplayName=@"Note";
            objAddressContactProperty.mContactPropId=propertyIndex;
            objAddressContactProperty.mContactDataType=@"Text";
            objAddressContactProperty.mContactPropertyString=[NSString stringWithString:(NSString*)temp];
            [objPhoneContact.mPropertyArray addObject:objAddressContactProperty];
            [objAddressContactProperty release];

            CFRelease(temp);
        }
        NSDate *localSyncDate=[[DataModel sharedDataModel] getValueForKey:LOCAL_SYNC_TIME_FOR_MODIFICATION];
        // Check modified Date
        CFDateRef modDate = ABRecordCopyValue(record, kABPersonModificationDateProperty);
        //NSDate *lastSyncTime = [[NSDate alloc] initWithString:lastSyncTimeStr];

       DLog(@"Record's modification date is: %@",(NSDate*)modDate);
//        NSLog(@"%@  and %@",modDate,localSyncDate);
        NSComparisonResult result = [localSyncDate compare:(NSDate*)modDate];

        if (result==-1) {
            if (appDelegate.shouldUpdateContactsCounter && appDelegate.isSyncInProgress!=0) {
                appDelegate.updatedInDeviceCounter++;
            }
            DLog(@"lastSyncTime is: %@",localSyncDate);
            DLog(@"Record's modification date is: %@",(NSDate*)modDate);
        }

        CFRelease(modDate);
        DLog(@"Date Comparison Result is: %d",result);

        objPhoneContact.mDateComparisionResult = result;
        /*switch (result)
        {
            case NSOrderedAscending:
                DLog(@"moddate=%@ is in future from lastsynctime=%@", modDate, lastSyncTime); 
                // the contact has been modified/updated
                break;
            case NSOrderedDescending:
                DLog(@"moddate=%@ is in past from lastsynctime=%@", modDate, lastSyncTime);
                // No need to update the contact
                CFRelease(record);
                [objPhoneContact release];
                continue;
            case NSOrderedSame: DLog(@"moddate=%@ is the same as lastsynctime=%@", modDate, lastSyncTime); break;
            default: DLog(@"erorr dates %@, %@", modDate, lastSyncTime); break;
        }*/

        // Get NoteToSelf
        /*kABPersonNoteProperty*/




        temp=ABRecordCopyValue(record, kABPersonOrganizationProperty);

        if (temp!=nil)
        {

            NSUInteger OrganizationPropertyId=3;
            ContactProperty* objCompanyContactProperty=[[ContactProperty alloc] init];


            NSMutableString *companyname=[NSMutableString stringWithFormat:@"%@",(NSString*)temp];

            objCompanyContactProperty.mContactPropertyString=[companyname stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];;


            objCompanyContactProperty.mDisplayName=@"Company";

            objCompanyContactProperty.mContactPropId=OrganizationPropertyId;
            objCompanyContactProperty.mContactDataType=@"Text";
            [objPhoneContact.mPropertyArray addObject:objCompanyContactProperty];
            [objCompanyContactProperty release];


            CFRelease(temp);
        //    temp=nil;
        }

        if (ABPersonHasImageData(record))
        {

            CFDataRef* dataRef=ABPersonCopyImageData(record);
            NSData* imageData=[[NSData alloc] initWithData:(NSData*)dataRef];;

            UIImage *img = [ImageUtility resizedImageWithImage:[UIImage imageWithData:imageData] scaledToDimension:CGSizeMake(50, 50)]; // Scale it to 50x50px

            objPhoneContact.mUserPhotoData = [NSData dataWithData:UIImageJPEGRepresentation(img, 1.0f)];

           [imageData release];
            if(dataRef)
                CFRelease(dataRef);
        }


        ABMutableMultiValueRef multi;
        int multiCount=0;


        multi = ABRecordCopyValue(record, kABPersonDateProperty);

        multiCount=ABMultiValueGetCount(multi);
        if(multiCount ==0)
        {

        }
        else
        {

            int propertyIndex=1402;   

            for (CFIndex i = 0; i < multiCount; i++) 
            {
                ContactProperty* objPhoneContactProperty=[[ContactProperty alloc] init];

                objPhoneContactProperty.mContactPropertyString=[NSString stringWithFormat:@"%@",(NSDate*)ABMultiValueCopyValueAtIndex(multi, i)];
                objPhoneContactProperty.mDisplayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                objPhoneContactProperty.mDisplayName=[objPhoneContactProperty.mDisplayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];

                objPhoneContactProperty.mContactPropId=propertyIndex;
                objPhoneContactProperty.mContactDataType=@"Date";

                [objPhoneContact.mPropertyArray addObject:objPhoneContactProperty];
                [objPhoneContactProperty release];

                propertyIndex++;
            }
        }
        if(multi)
            CFRelease(multi);



        multi = ABRecordCopyValue(record, kABPersonPhoneProperty);

        NSUInteger phoneIndex_mobile=11;
        NSUInteger phoneIndex_iPhone=31;
        NSUInteger phoneIndex_home=51;
        NSUInteger phoneIndex_work=71;
        NSUInteger phoneIndex_main=91;
        NSUInteger phoneIndex_home_fax=111;
        NSUInteger phoneIndex_work_fax=131;
        NSUInteger phoneIndex_pager=151;
        NSUInteger phoneIndex_other=171;  

        multiCount=ABMultiValueGetCount(multi);
        if(multiCount ==0)
        {
            //objPhoneContact.mPhoneNum=@"";
        }
        else 
        {
            for( int i=0; i < multiCount; i++)
            {

                ContactProperty* objPhoneContactProperty=[[ContactProperty alloc] init];

                objPhoneContactProperty.mContactPropertyString=(NSString*)ABMultiValueCopyValueAtIndex(multi, i);
                objPhoneContactProperty.mDisplayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                objPhoneContactProperty.mDisplayName=[objPhoneContactProperty.mDisplayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];
                if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"mobile"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_mobile;
                    phoneIndex_mobile++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"iPhone"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_iPhone;
                    phoneIndex_iPhone++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"home"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_home;
                    phoneIndex_home++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"work"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_work;
                    phoneIndex_work++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"main"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_main;
                    phoneIndex_main++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"HomeFAX"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_home_fax;
                    phoneIndex_home_fax++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"WorkFAX"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_work_fax;
                    phoneIndex_work_fax++;
                }
                else if([objPhoneContactProperty.mDisplayName caseInsensitiveCompare:@"pager"]==NSOrderedSame)
                {
                    objPhoneContactProperty.mContactPropId=phoneIndex_pager;
                    phoneIndex_pager++;
                }
                else
                {
                    NSRange range1,range2,range3;

                    range1=[objPhoneContactProperty.mDisplayName rangeOfString:@"mobile" options:NSCaseInsensitiveSearch];
                    range2=[objPhoneContactProperty.mDisplayName rangeOfString:@"home" options:NSCaseInsensitiveSearch];
                    range3=[objPhoneContactProperty.mDisplayName rangeOfString:@"work" options:NSCaseInsensitiveSearch];

                    if (range1.location!=NSNotFound) 
                    {
                        objPhoneContactProperty.mContactPropId=phoneIndex_mobile;
                        phoneIndex_mobile++;
                    }
                    else if (range2.location!=NSNotFound) 
                    {
                        objPhoneContactProperty.mContactPropId=phoneIndex_home;
                        phoneIndex_home++;
                    }
                    else if (range3.location!=NSNotFound) 
                    {
                        objPhoneContactProperty.mContactPropId=phoneIndex_work;
                        phoneIndex_work++;
                    }
                    else 
                    {
                        objPhoneContactProperty.mContactPropId=phoneIndex_other;
                        phoneIndex_other++;
                    }
                }

                objPhoneContactProperty.mContactDataType=@"Phone";

                [objPhoneContact.mPropertyArray addObject:objPhoneContactProperty];
                [objPhoneContactProperty release];
            }
        }

        if(multi)
            CFRelease(multi);



        multi=ABRecordCopyValue(record,kABPersonEmailProperty);

        NSUInteger emailIndex_home=301;
        NSUInteger emailIndex_work=321;
        NSUInteger emailIndex_other=341;  //~400

        multiCount=ABMultiValueGetCount(multi);
        if(multiCount ==0)
        {
            //objPhoneContact.mEmailId=@"";
        }
        else 
        {
            for( int i=0; i < multiCount; i++)
            {
                ContactProperty* objEmailContactProperty=[[ContactProperty alloc] init];

                objEmailContactProperty.mContactPropertyString=(NSString*)ABMultiValueCopyValueAtIndex(multi, i);
                objEmailContactProperty.mDisplayName=(NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
                objEmailContactProperty.mDisplayName=[objEmailContactProperty.mDisplayName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"_$!<>"]];


                if([objEmailContactProperty.mDisplayName caseInsensitiveCompare:@"home"]==NSOrderedSame)
                {
                    objEmailContactProperty.mContactPropId=emailIndex_home;
                    emailIndex_home++;
                }
                else if([objEmailContactProperty.mDisplayName caseInsensitiveCompare:@"work"]==NSOrderedSame)
                {
                    objEmailContactProperty.mContactPropId=emailIndex_work;
                    emailIndex_work++;
                }

                else 
                {
                    objEmailContactProperty.mContactPropId=emailIndex_other;
                    emailIndex_other++;
                }

                objEmailContactProperty.mContactDataType=@"Email";

                [objPhoneContact.mPropertyArray addObject:objEmailContactProperty];
                [objEmailContactProperty release];
            }
        }

        if(multi)
            CFRelease(multi);



        NSUInteger imIndex_HomeUser=1601;
        NSUInteger imIndex_HomeService=1602;
        NSUInteger imIndex_WorkUser=1651;
        NSUInteger imIndex_WorkService=1652;
        NSUInteger imIndex_OtherUser=1701;
        NSUInteger imIndex_OtherService=1702;


        multi = ABRecordCopyValue(record, kABPersonInstantMessageProperty);

        multiCount=ABMultiValueGetCount(multi);
        if(multiCount ==0)
        {
            //objPhoneContact.mEmailId=@"";
        }
        else 
        {
            for(int i=0;i<multiCount;i++)
            {

                int propertyIndexUser=0;
                int propertyIndexService=0;
于 2012-05-08T06:02:14.720 回答