Objective c ABR多值参考零值检查
我正在尝试获取联系人的家庭电子邮件属性。它工作正常,但我不确定我是否检查了home email属性是否为Objective c ABR多值参考零值检查,objective-c,ios,contacts,null,abaddressbook,Objective C,Ios,Contacts,Null,Abaddressbook,我正在尝试获取联系人的家庭电子邮件属性。它工作正常,但我不确定我是否检查了home email属性是否为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
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";
}
}
我的问题是:在这一行中,如果((uu bridge\u transfer NSString*)ABMultiValueCopyValueAtIndex(emailsMultiValueRef,emailsCount)!=NULL)
,我是否将作为字符串复制的值与nil
或NULL
进行比较?我不确定nil值检查当前是否有效
提前谢谢 我用正确的方法检查它是否为零(通过比较
ABMultiValueCopyValueAtIndex(emailsMultiValueRef,emailscont)
和NULL
)。我用正确的方法检查它是否为零(通过比较ABMultiValueCopyValueAtIndex(emailsMultiValueRef,emailscont)的值)
到NULL
)。以下是正确的描述-
如果您只想填充通讯簿,并且在选择任何联系人后,您希望此人有或没有电子邮件,请执行此操作-->
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)在选择person:(ABRecordRef)person后,peoplePickerNavigationController应继续{
NSMUTABLEARRY*个人邮件=[NSMUTABLEARRY new];
ABMutableMultiValueRef multi=ABRecordCopyValue(person,kABPersonEmailProperty);
如果(ABMultiValueGetCount(multi)>0){
对于(CFIndex i=0;i
}以下是正确的描述- 如果您只想填充通讯簿,并且在选择任何联系人后,您希望此人有或没有电子邮件,请执行此操作-->
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)在选择person:(ABRecordRef)person后,peoplePickerNavigationController应继续{
NSMUTABLEARRY*个人邮件=[NSMUTABLEARRY new];
ABMutableMultiValueRef multi=ABRecordCopyValue(person,kABPersonEmailProperty);
如果(ABMultiValueGetCount(multi)>0){
对于(CFIndex i=0;i
}试试这个。我可以得到电子邮件地址没有任何问题
-(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;
}
试试这个。我可以得到电子邮件地址没有任何问题
-(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;
}
@哈德利-它对我有效,所以这意味着你的代码/联系人数据库有错误。你本可以就你的问题发表评论,我本可以尝试修复它,但你对我的问题投了一个完全正确的答案。我只联系了名字和姓氏,没有其他详细信息,我按照你的建议检查了它,尽管为空,但没有得到它。我做了大量的研究和开发,最终发现,这个条件最适合ABMultiValueGetCount(emailsMultiValueRef)>0。@Hadley-你和我正在尝试完成不同的事情;我正在检查用户是否有家庭电子邮件,而您正在检查用户是否有任何电子邮件。@Hadley-它对我有效,因此这意味着您的代码/联系人数据库有错误。你本可以就你的问题发表评论,我本可以尝试修复它,但你对我的问题投了一个完全正确的答案。我只联系了名字和姓氏,没有其他详细信息,我按照你的建议检查了它,尽管为空,但没有得到它。我做了大量的研究和开发,最终发现,这个条件最适合ABMultiValueGetCount(emailsMultiValueRef)>0。@Hadley-你和我正在尝试完成不同的事情;我正在检查用户是否有家庭电子邮件,而您正在检查用户是否有任何电子邮件。