1

I am trying to get the home email property of a contact. It works fine, but I'm not sure if I check whether or not I correctly check if the home email property is nil.

//Since there are multiple email labels, I iterate through them and check which one matches the string "Home" and that is the home email
if([emailLabel isEqualToString:@"Home"]){

        //Here is where I check if there is actually a home email value        
        if ((__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount) != NULL){

            email = (__bridge_transfer NSString *)ABRecordCopyValue(currentPerson, kABPersonEmailProperty);
        }   

        //If the email property does not exist
        else{

            email = @"NULL";
        }
    }

My question is this: in this line if ((__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount) != NULL), do I compare the value copied as a string to nil or NULL? I'm not sure if the nil value checking is currently working.

Thanks in advance!

pasawaya
  • 11,515
  • 7
  • 53
  • 92

3 Answers3

1

Try this. I'm able to get email address without any issue.

-(BOOL)peoplePickerNavigationControllerenter code here:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

return YES;

}


-(BOOL)peoplePickerNavigationController(ABPeoplePickerNavigationController*)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier
{


   if (kABPersonEmailProperty == property)
 {

        ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);

        NSString *email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multi, identifier);

        NSLog(@"email: %@", email);

        [self dismissModalViewControllerAnimated:YES];

        return NO;
    }
    return YES;
}
Automate This
  • 30,726
  • 11
  • 60
  • 82
Baljeet Singh
  • 453
  • 5
  • 15
0

I was checking if it was nil the correct way (By comparing the value of ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount) to NULL).

pasawaya
  • 11,515
  • 7
  • 53
  • 92
  • @Hadley - It worked for me, so that means there's an error with your code/contacts database. You could've posted a comment with your problem and I could've tried to fix it but you went ahead and down voted a perfectly correct answer to my question. – pasawaya Jul 20 '12 at 22:19
  • i have a contact with only first and last name and no other details, and i checked it as you suggested and in spite of being NULL , it didn't get it. I did a lot of R&D and finally discovered, this condition to be the best suitable ABMultiValueGetCount(emailsMultiValueRef)>0 . – HarshIT Jul 21 '12 at 04:48
  • @Hadley - You and I are trying to accomplish different things; I am checking if the user has a **home** email, while you are checking if the user has any email at all. – pasawaya Jul 21 '12 at 05:28
0

Here is proper description-

If u just want to populate address book and after selection any contact you want that person has email or not then do this -->

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




NSMutableArray   *personEmails=[NSMutableArray new];
ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);


    if (ABMultiValueGetCount(multi) > 0) {

        for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) {
            CFStringRef emailRef = ABMultiValueCopyValueAtIndex(multi, i);
            [personEmails addObject:(NSString *)emailRef];
            CFRelease(emailRef);
        }
    }
    else{

        UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Oops!! \ue403" message:@"No Email addredd found !\n\n " delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil];
        [errorAlert show];
        [errorAlert release];
    }
    CFRelease(multi);

}

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
Nagendra Tripathi
  • 923
  • 12
  • 23