2
通訊錄中未添加聯繫人。錯誤將人員保存到iOS 9中的AddressBook,但在iOS 6中工作。當我添加聯繫人,然後執行if塊以將日誌錯誤保存到AddressBook。使用地址簿框架iOS 9導出聯繫人時出錯?
-(void)addContactToPhoneBook{
ABPeoplePickerNavigationController *peoplePicker=[[ABPeoplePickerNavigationController alloc] init];
addressBook = [peoplePicker addressBook];
// create person record
person = ABPersonCreate();
cfError = nil;
if (firstName) {
ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)(firstName) , nil);
}
if (jobTitle) {
ABRecordSetValue(person, kABPersonJobTitleProperty,(__bridge CFTypeRef)(jobTitle), nil);
}
if (personEmail)
{
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFStringRef) personEmail, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, nil);
CFRelease(emailMultiValue);
}
if (phoneNo)
{
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
NSArray *venuePhoneNumbers = [phoneNo componentsSeparatedByString:@" or "];
for (NSString *venuePhoneNumberString in venuePhoneNumbers)
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, (__bridge CFStringRef) venuePhoneNumberString, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
CFRelease(phoneNumberMultiValue);
}
// add address
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
ABMultiValueAddValueAndLabel(multiAddress, (__bridge CFDictionaryRef) addressDictionary, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress, NULL);
CFRelease(multiAddress);
//Add person Object to addressbook Object.
ABAddressBookAddRecord(addressBook, person, &cfError);
if (ABAddressBookSave(addressBook, nil))
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Contact added sucessfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
NSLog(@"\nPerson Saved successfuly");
} else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Failed to add contact" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
NSLog(@"\n Error Saving person to AddressBook");
}
}
請再次檢查問題。 – niks290192