アドレス帳 - Linked ContactのEメールを選択してください
-
26-12-2019 - |
質問
下記の委任コールバックで選択した電子メールプロパティを取得しようとしています
-(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;
}
.
しかし、リンクされた連絡先(単一の電子メールを持つ)の電子メールプロパティを選択した場合、最初のEメール-IDの1次連絡先が取得されます。 例:John - john@gmail.com john26@gmail.com Roger(リンク連絡先) - roger@gmail.com
Roger@gmail.comを選択したとき、john@gmail.comが得られます。
解決
私は同じ問題を抱えています。複数の電子メールアドレスを持つアカウントを選択すると、間違ったEメールが表示されます。選択したABMUTABLEMULTIVALEREFをループするとき...
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
.
回避策は、まずNULLラベルを除外することを目的としています.AbMultivalueIdentifier 'fits'がヌルラベルに戻されない場合は、あなたが何かを見つけたのでない限り?
編集:これは私にとって機能します。
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);
}
. 所属していません StackOverflow