2012-06-26 48 views
1

我試圖獲取聯繫人的主電子郵件屬性。它工作正常,但我不確定是否檢查我是否正確檢查家庭電子郵件屬性是否爲nilABMultiValueRef無值檢查

//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的價值?我不確定是否零值檢查目前正在工作。

在此先感謝!

回答

0

我正在檢查它是否是正確的方式(通過比較ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount)NULL的值)。

+0

它不工作,但 – HarshIT

+0

它在崩潰,如果我在哪裏比較..... – HarshIT

+0

@Hadley聲明 - 它的工作對我來說,這樣就意味着有一個與你的代碼/聯繫人數據庫錯誤。你可以發佈你的問題的評論,我可以試着修復它,但你繼續投票給我的問題一個完全正確的答案。 – pasawaya

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

}

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