I noticed an error in the logic that we use to handle the selection of a specific letter for the contact submitted by ABPeoplePickerNavigationController. The error occurs when the contact we have has Connected contacts from Twitter or Facebook.
I double-checked our logic against several related StackOverflow questions, and I seem to be doing everything “correctly”:
Here is the code to download ABPeoplePicker after clicking the button:
- (void)setUpChooseContactButton
{
@weakify(self)
[self.chooseContactButton addEventHandler:^(id sender) {
@strongify(self)
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.displayedProperties = @[@(kABPersonEmailProperty)];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
} forControlEvents:UIControlEventTouchUpInside];
}
, , :
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
if (property == kABPersonEmailProperty)
{
ABMultiValueRef multiEmail = ABRecordCopyValue(person, kABPersonEmailProperty);
CFIndex selectedIndex = ABMultiValueGetIndexForIdentifier(multiEmail, identifier);
CFStringRef selectedEmail = ABMultiValueCopyValueAtIndex(multiEmail, selectedIndex);
NSLog(@"Doing something with %@", selectedEmail);
if (selectedEmail) CFRelease(selectedEmail);
if (multiEmail) CFRelease(multiEmail);
}
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
, , . Facebook, , .
, , John Snow, , iCloud, 2 Gmail Facebook.
, 5 :
- john.snow@gmail.com
- jsnow@gmail.com
- lordsnow@nightswatch.org
- john.snow@facebook.com
- john@winterfellstarks.com
.
, lordsnow@nightswatch.org( 2 ) , shouldContinueAfterSelecting NSLog , :
(lldb) po multiEmail
ABMultiValueRef 0x17737ca0 with 8 value(s)
0: null (0x3b864a60) - john@winterfellstarks.com (0x15d4bd30)
1: null (0x3b864a60) - lordsnow@nightswatch.org (0x15f0f2d0)
2: null (0x3b864a60) - john.snow@gmail.com (0x15f3b470)
3: null (0x3b864a60) - jsnow@gmail.com (0x15d02060)
4: _$!<Work>!$_ (0x15f352d0) - john.snow@facebook.com (0x15f3d480)
5: _$!<Other>!$_ (0x15fbeae0) - john.snow@gmail.com (0x15f2a170)
6: _$!<Other>!$_ (0x15de9ce0) - jsnow@gmail.com (0x15f0f0e0)
7: _$!<Other>!$_ (0x15f0a110) - lordsnow@nightswatch.org (0x15f00830)
(lldb) po selectedIndex
2
(lldb) po identifier
2
(lldb) po selectedEmail
john.snow@gmail.com
.