pasawaya
pasawaya

Reputation: 11595

ABMultiValueRef nil value checking

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!

Upvotes: 1

Views: 1281

Answers (3)

Nagendra Tripathi
Nagendra Tripathi

Reputation: 923

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

}

Upvotes: 0

Baljeet Singh
Baljeet Singh

Reputation: 453

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

Upvotes: 1

pasawaya
pasawaya

Reputation: 11595

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

Upvotes: 0

Related Questions