Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sachin.singh

macrumors newbie
Original poster
Oct 19, 2008
17
0
Hi All ,

I am using the below code to fetch contacts from ABAddressBook . It causes an animation glitch while pushing my viewcontroller into the navigation controller . below is my code for fetching contacts from iphone address book. can anyone help me ?
Code:
ABAddressBookRef m_addressbook = ABAddressBookCreate();
    if (!m_addressbook) {
        NSLog(@"opening address book");
    }

    // can be cast to NSArray, toll-free

    m_pAddressBookArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(m_addressbook);
    //NSLog(@"the array is %@",m_pAddressBookArray);



    for(int i = 0; i<[m_pAddressBookArray count]; i++)
    {
        Contact *aContact = [Contact new];
        ABRecordRef ref = CFArrayGetValueAtIndex((CFArrayRef)m_pAddressBookArray,i);
        UIImage *image;
        if(ABPersonHasImageData(ref)){
            image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(ref)];
        }else{
            image = [UIImage imageNamed:@"userphoto37x37.png"];
        }
        [aContact setAvatarImage:image];
        //NSData *imageData = UIImagePNGRepresentation(image);
        NSString *emailID;
        NSMutableArray *emails = [[NSMutableArray alloc] init];
        ABMutableMultiValueRef emailMulti = ABRecordCopyValue(ref, kABPersonEmailProperty);
        for (int i = 0; i < ABMultiValueGetCount(emailMulti); i++) {
            NSString *anEmail = [(NSString*)ABMultiValueCopyValueAtIndex(emailMulti, i) autorelease];
            [emails addObject:anEmail];
        }
        if([emails count]!=0)
            emailID = [emails objectAtIndex:0];


        [aContact setEmailID:emailID];
        //[addressbookContacts addObject:[NSDictionary dictionaryWithObjectsAndKeys:(NSString *)ABRecordCopyCompositeName(ref), @"name",emailID,@"email",imageData,@"avtar",nil]];
        [addressbookContacts addObject:aContact];
        [aContact release];
        emailID = @"";
        [emails release];

    }
    self.m_pAddressBookArray = nil;

Is anything wrong I am doing my code ? Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.