0

I am attempting to access the anniversary date property from the contacts in address book. I have already accessed other properties such as the name and company. myPerson was created from a custom class, and it has an NSDate property called date.

ABAddressBookRef addressBook2  = ABAddressBookCreateWithOptions(NULL, NULL);
NSMutableArray *people = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook2);
ABRecordRef r = (__bridge ABRecordRef)([people objectAtIndex:i]);
NSDateFormatter *dF = [[NSDateFormatter alloc]init];
[dF setDateFormat:@"dd-MM-yyyy"];
NSDate *dS = [[NSDate alloc] init];
dS=[dF dateFromString:(__bridge NSString *)(ABRecordCopyValue(r, kABPersonAnniversaryLabel))];
myPerson.date = dS;

The application builds but gives me an EXC_BAD_ACCESS error and an value conversion issue warning on the line where dS gets its value.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Contact dates are like phone numbers and email addresses. A user can have more than one. You need to get the list of dates and find the one with the desired label. – rmaddy Aug 07 '14 at 22:44
  • See http://stackoverflow.com/questions/14234029/anniversary-from-contacts-in-iphone/14235238#14235238 for how to find the anniversary date of a contact. – rmaddy Aug 07 '14 at 22:46
  • BTW - you really need to update your code to deal with checking and getting permission to access the user's contacts. – rmaddy Aug 07 '14 at 22:57
  • I actually have much more code than this that deals with getting permission I just condensed it to put in this question – user12394620 Aug 09 '14 at 20:56

0 Answers0