0

ABPeoplePickerNavigationController を使用して、連絡先帳のエントリから電子メール アドレスと電話番号の配列を収集しています。90% の確率で正常に動作しますが、一部のテスターからクラッシュが報告されています。クラッシュ レポートには、CFRelease でクラッシュしていると書かれています...自分のコードが正しいと信じている理由がわかりません。見てみましょう:

ABProfile *selectedUser = [[ABProfile alloc]init];

ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);

NSArray *emailArray;

if (ABMultiValueGetCount(emails) > 0) {
    emailArray = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(emails);
}

CFRelease(emails);

ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);

NSMutableArray *phonesArray = [[NSMutableArray alloc]initWithCapacity:1];

for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:1];

    CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);

    CFStringRef locLabel = ABMultiValueCopyLabelAtIndex(phones, j);
    NSString *phoneLabel =(__bridge_transfer NSString*) ABAddressBookCopyLocalizedLabel(locLabel);

    CFRelease(locLabel);

    [dict setValue:phoneLabel forKey:@"label"];
    NSString *phoneNumber = (__bridge_transfer NSString *)phoneNumberRef;

    [dict setValue:phoneNumber forKey:@"number"];

    [phonesArray addObject:dict];
}

selectedUser.phones = phonesArray;

CFRelease(phones);
4

1 に答える 1

0

ABMultiValueCopyLabelAtIndexNULL見つからない場合は戻る可能性があり、CFRelease(NULL)クラッシュします。locLabel私はそれを使って何かをする前に存在することを確認するためにチークします。

于 2012-07-05T17:00:01.157 に答える