Реализация адресной книги не работает

Я использую XCode 4.2 для разработки функции добавления контакта в адресную книгу, вот мой код

 ABAddressBookRef *iPhoneAddressBook = ABAddressBookCreate();
 ABRecordRef contact = ABPersonCreate();

 //add infos
 ABRecordSetValue(contact, kABPersonFirstNameProperty,(__bridge_retained CFStringRef)firstName, nil);
 ABRecordSetValue(contact, kABPersonLastNameProperty,(__bridge_retained CFStringRef)lastName, nil);
 ABRecordSetValue(contact, kABPersonOrganizationProperty, (__bridge_retained CFStringRef)organization, nil);
 ABRecordSetValue(contact, kABPersonJobTitleProperty, (__bridge_retained CFStringRef)title, nil);


 ABMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiRealPropertyType);


 ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workTel, kABPersonPhoneMainLabel, NULL);
 ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workFax, kABPersonPhoneWorkFAXLabel, NULL);

 ABRecordSetValue(contact, kABPersonPhoneProperty, multiPhone, nil);
 CFRelease(multiPhone);

 ABMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);

 ABMultiValueAddValueAndLabel(multiEmail, (__bridge_retained CFStringRef)email, kABWorkLabel, NULL);

 ABRecordSetValue(contact, kABPersonEmailProperty, multiEmail, nil);

 CFRelease(multiEmail);
// address

ABMultiValueRef multiAddress =ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc]init];
[addressDict setObject:address forKey:(NSString *) kABPersonAddressStreetKey];
[addressDict setObject:city forKey:(NSString *) kABPersonAddressCityKey];
[addressDict setObject:province forKey:(NSString *) kABPersonAddressStateKey];
[addressDict setObject:postalCode forKey:(NSString *) kABPersonAddressZIPKey];
[addressDict setObject:address forKey:(NSString *) kABPersonAddressCountryKey];

ABMultiValueAddValueAndLabel(multiAddress, (__bridge_retained CFStringRef)addressDict, kABWorkLabel, NULL);
ABRecordSetValue(contact, kABPersonAddressProperty, multiAddress, NULL);


CFRelease(multiAddress);

ABMultiValueRef multiURL =ABMultiValueCreateMutable(kABMultiRealPropertyType);
ABMultiValueAddValueAndLabel(multiURL, (__bridge_retained CFStringRef)link, kABPersonURLProperty, NULL);
CFRelease(multiURL);



 ABAddressBookAddRecord(iPhoneAddressBook, contact, nil);

 BOOL didAdd = ABAddressBookSave(iPhoneAddressBook, nil);

 CFRelease(contact);
 CFRelease(iPhoneAddressBook);

 //notifying the user that it was stored in his address book
 if (didAdd) {


 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirmation" 
 message:@"Contact Info successfully added to the Address Book" 
 delegate:self 
 cancelButtonTitle:@"OK" 
 otherButtonTitles:nil];
 [alert show];
 }

программа компилируется и останавливается на этой строке:

ABMultiValueAddValueAndLabel(multiPhone, (__bridge_retained CFStringRef)workTel, kABPersonPhoneMainLabel, NULL);

Я получаю эту ошибку (зеленым цветом)

Thread 1

какая-нибудь подсказка? что не так в коде?

1 ответ

Это определение функции, в которой возникает ваша ошибка:

bool ABMultiValueAddValueAndLabel (
   ABMutableMultiValueRef multiValue,
   CFTypeRef value,
   CFStringRef label,
   ABMultiValueIdentifier *outIdentifier
);

Похоже, вы переключили 2-й и 3-й аргументы, верно?

Другие вопросы по тегам