0

I am working in projects that need to fetch all information of single person from contacts.

I can Fetch all phone,Emails or other properties by using this code

- (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));
}

}

But in that I need to write this code for all attributes. And you know there are so many fields like nickname,birthday and etc..

So, is there any way that I can get the all attributes of single person ?

Sarafaraz Babi
  • 480
  • 6
  • 18

2 Answers2

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];
    }
Saad
  • 8,857
  • 2
  • 41
  • 51
  • you should consider posting only relevant code in your answer specially when it doesn't fit in the word limit. – Vin May 08 '12 at 06:05
  • hello Saad, We can get the attributes like this but it's too lengthy. I think if we have a person's reference then we might get that how many and which property that person contain.so it's compress our coding. – Sarafaraz Babi May 08 '12 at 06:47
  • you can't load properties as you are saying. you will have to load it one by one – Saad May 08 '12 at 06:49
0

NO, you will have to do this for all properties, no way except this. how ever, here is code for all this to get the detail. may some thing extra here because i did it for my app. not general.Here Contact is my own object which contains data like name, company and a property array that contains properties. This is not perfect code but just to show u a model and is in two parts:

-(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;
Vin
  • 10,517
  • 10
  • 58
  • 71
Saad
  • 8,857
  • 2
  • 41
  • 51