72662

ABAddressBook get birthday property

Question:

I'm trying to get the birthday property from ABAddressBook on my iphone. I've looked through some discussions over the web and mostly recommends the same answer, which I have tried myself as below. But this still doesn't work for me so I wonder if i missed something else....

dayFormatter = [[[NSDateFormatter alloc] init]autorelease]; [self.dayFormatter setDateFormat:@"MMMM d"]; NSString* today = [dayFormatter stringFromDate:[NSDate date]]; NSLog(@"today:%@", today); NSLog(@"date:%@", [NSDate date]); // this works fine NSDate *bday = (NSDate*)ABRecordCopyValue(personRecord,kABPersonBirthdayProperty); NSLog(@"bdayyyy:%@", bday); // this doesn't work. NSString* personBday = [dayFormatter stringFromDate:bday]; NSLog(@"Bday:%@", personBday);

any help is much appreciated.. Thanks.

Answer1:

This works for me:

NSDate* birthDate = (__bridge_transfer NSDate*)ABRecordCopyValue(addressBookContact, kABPersonBirthdayProperty);

Answer2:

Try this:

ABAddressBookRef myAddressBook = ABAddressBookCreate(); NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook); for (id record in allPeople) { NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init]; CFTypeRef bDayProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty); if (ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty)) { NSDate *date=(NSDate*)bDayProperty; [newRecord setObject:date forKey:@"birthDate"]; date=nil; [date release]; } CFRelease(myAddressBook); }

Recommend

  • iOS status bar overlaps with webView
  • Deleting Sharepoint Files using XMLHTTP
  • What does “bottleneck” mean in terms of bandwidth?
  • passed object nil into my second view
  • iOS6 TimeInterval bug
  • How can I replace certain string in a string in Python?
  • How to implment laps in Stop Watch iphone app
  • UIView drawRect vs initWithFrame
  • Jackon 2.4.2 failing to deserialize valid date, even after specifying date format
  • createRecord with ember-data + ember-data-django-rest-adapter
  • how to find the index position of the ARRAY Where NSPredicate pick the value. I use filteredArrayUsi
  • Accessing an Object from Class type(+) method in iPhone & Cocos2d?
  • MKOverlayView performance
  • How to mock current date?
  • Why won't my UITableViewCell deselect and update its text?
  • Get count of created entries for each day
  • How to parsing NSDate to RFC 822 always use in English?
  • iOS Date formatting
  • How to format data from string variable
  • Add Labeltext on Mkannotation image
  • Send emails through VB6 if no email client
  • What is this iOS exception with NSCFType?
  • how to solve invalid conversion specifier warning in iphone app
  • Check for zero lines output from command over SSH
  • NSScanner Loop Question
  • Lost migrations and Azure database is now out of sync
  • Get one-time binding to work for ng-if
  • Pass value from viewmodel to script in zk
  • Dynamically accessing properties of knockoutjs observable array
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Eraser for UIBezierPath
  • Large data - storage and query
  • How can I estimate amount of memory left with calling System.gc()?
  • WOWZA + RTMP + HTML5 Playback?
  • Compare two NSDates in iPhone
  • Load html files in TinyMce
  • Hits per day in Google Big Query