ABMultiValueRef nil值检查

时间:2012-06-26 20:50:33

标签: objective-c ios contacts null abaddressbook

我正在尝试获取联系人的主页电子邮件属性。它工作正常,但我不确定我是否检查我的主电子邮件属性是否为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";
        }
    }

我的问题是:在这一行if ((__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount) != NULL)中,我是否将复制为字符串的值与nilNULL进行比较?我不确定nil值检查当前是否正常工作。

提前致谢!

3 个答案:

答案 0 :(得分:1)

试试这个。我可以毫无问题地获得电子邮件地址。

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

答案 1 :(得分:0)

我正在检查它是否是正确的方式(通过比较ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount)NULL的值)。

答案 2 :(得分:0)

这是正确的描述 -

如果您只想填写地址簿,并在选择任何您希望该人收到电子邮件的联系人后,请执行此操作 - >

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

}