ユーザーのアドレス帳を開く iPhone アプリを開発しています。ユーザーが電話帳から選択した人の電話番号を取得します。アドレス帳に 2 つ以上の電話番号を持つ人物がいて、ユーザーが連絡先の 1 つを削除し、そのユーザーがその人物から連絡先を選択した後、「ABPeoplePickerNavigationControllerDelegate」メソッド -
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_AVAILABLE_IOS(8_0);
間違った識別子を与えます.それ以外の場合は正常に機能しています.
アドレス帳から選択した電話番号を取得するために使用しているコードは次のとおりです。デリゲートメソッドが正しい識別子を与えていない理由を知っている人はいますか?
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
if (property == kABPersonPhoneProperty)
{
NSString* phoneNumber = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
property);
if (ABMultiValueGetCount(phoneNumbers) > 0)
{
CFIndex index = ABMultiValueGetIndexForIdentifier(phoneNumbers, identifier);
*//**** since identifier is wrong it returns index as -1 and app crashes in the below line *****
phoneNumber = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, index);
}
}