1

我正在尝试获取联系人的家庭电子邮件属性。它工作正常,但我不确定我是否检查我是否正确检查家庭电子邮件属性是否为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)中,我是否将作为字符串复制的值与nilor进行比较NULL?我不确定 nil 值检查当前是否有效。

提前致谢!

4

3 回答 3

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;
}
于 2014-03-04T05:00:19.927 回答
0

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

于 2012-07-06T00:22:43.290 回答
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);

}

于 2013-05-23T07:54:26.843 回答