문제

아래에 설명 된 대리인 콜백에서 선택한 전자 메일 속성을 가져 오려고합니다

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
        if (property==kABPersonEmailProperty) {
            ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
            if (ABMultiValueGetCount(emails) > 0) {
                NSString *email = (__bridge_transfer NSString*)
                ABMultiValueCopyValueAtIndex(emails, ABMultiValueGetIndexForIdentifier(emails,identifier));
                [recipientEmail setText:email];
                [peoplePicker dismissViewControllerAnimated:YES completion:nil];
            }
             CFRelease(emails);
        }
        return NO;
    }
.

그러나 링크 된 연락처의 전자 메일 속성을 선택하면 ID를 0으로 가져옵니다. 결과적으로 1 차 연락처의 첫 번째 이메일 ID를 얻습니다. 예 : john - john@gmail.com. john26@gmail.com. Roger (연결된 연락처) - roger@gmail.com

roger@gmail.com을 선택하면 john@gmail.com을 얻습니다.

도움이 되었습니까?

해결책

이 문제가 있습니다.여러 전자 메일 주소로 계정을 선택할 때 잘못된 이메일을받습니다.선택한 abmutablemultivalueref를 반복 할 때 ...

for (CFIndex ix = 0; ix < ABMultiValueGetCount(emails); ix++) {
   CFStringRef label = ABMultiValueCopyLabelAtIndex(emails, ix);
   CFStringRef value = ABMultiValueCopyValueAtIndex(emails, ix);
   NSLog(@"I have a %@ address: %@", label, value);
   if (label) CFRelease(label);
   if (value) CFRelease(value);
}
.

... 동일한 주소를 여러 번받지 만 null 레이블이있는 일부입니다.

> I have a (null) address: john@home.com
> I have a _$!<Work>!$_ address: jsmith@work.com
> I have a _$!<Home>!$_ address: john@home.com
.

해결 방법을 먼저 널 레이블을 필터링하는 것입니다. AbmultivalueIdentifier 'fits'및 null 레이블로 되돌리지 않으면을 참조하십시오.당신이 뭔가를 발견하지 못한다면?

편집 : 이것은 나를 위해 작동합니다.

    NSMutableArray *labeled = [NSMutableArray new];
    ABMutableMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
    for (CFIndex ix = 0; ix < ABMultiValueGetCount(emails); ix++) {
        CFStringRef label = ABMultiValueCopyLabelAtIndex(emails, ix);
        CFStringRef value = ABMultiValueCopyValueAtIndex(emails, ix);
        if (label != NULL) {
            [labeled addObject:(NSString *)CFBridgingRelease(value)];
        }
        if (label) CFRelease(label);
        if (value) CFRelease(value);
    }
    NSString *email;
    if (labeled.count > identifier) {
        email = [labeled objectAtIndex:identifier];
    } else {
        CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, identifier);
        email = (NSString *)CFBridgingRelease(emailRef);
    }
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top