我创建了一个视图控制器,它使用新条目为第一次访问创建新记录。不幸的是,新记录没有被存储。当我导航到前一页并返回时,我可以告诉它,不会显示新记录。我已经显示了“user”,它是一个单独的NSString。我还得到一条NSLog消息,没有未保存的更改(请参阅下面的语句)。附上我的代码:
(void)viewDidLoad { [super viewDidLoad];
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *people = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
person = ABPersonCreate();
bool didSet = ABRecordSetValue(person, kABPersonFirstNameProperty, user, &error);
if (!didSet) {
NSLog(@"the RecordSetValue error is %@", error);
}
ABMutableMultiValueRef multiURL = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiURL,user,kABPersonHomePageLabel,NULL);
ABRecordSetValue(person, kABPersonURLProperty, multiURL, &error);
CFRelease(multiURL);
//save values to address book
NSLog(@"does address book have unsaved changes? %@",ABAddressBookHasUnsavedChanges(addressBook) ? @"YES" : @"NO");
bool didSave = ABAddressBookSave(addressBook, &error);
if (!didSave) {
NSLog(@"the save to address book error is %@", error);
}
CFRelease(addressBook);
感谢您的帮助。
答案 0 :(得分:2)
您创建了ABPerson
条记录,但从未使用ABAddressBookAddRecord
将其添加到地址簿中。这也是ABAddressBookHasUnsavedChanges
返回NO
的原因。