开发者

iphone address book not saving records

I created a view controller which creates new records for the first visit with a new entry. Unfortunately, the new record is not 开发者_运维技巧being stored. I can tell this when I navigate to the prior page and return, the new record is not displayed. I have displayed "user", which is an NSString separately. I also get a NSLog message that there are no unsaved changes (see if statement below). Attached is my code:

(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);

Thanks for your help.


You created a ABPerson record, but never added it to your address book using ABAddressBookAddRecord. That would also be why ABAddressBookHasUnsavedChanges is returning NO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜