I'm trying to figure how you can add a birthday to an ABRecordRef without a year (i.e May 5 instead of May 5 1985). Is this possible?

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
NSDate *date = [df dateFromString:[result valueForKey:@"birthday"]];

if(date == nil)
{
       df = [[NSDateFormatter alloc] init];
       [df setDateFormat:@"MM/dd"];
       date = [df dateFromString:[result valueForKey:@"birthday"]];
 }

 ABRecordSetValue(person, kABPersonBirthdayProperty, (__bridge CFDateRef)date, nil);

If there's no year attached to the date string it defaults to 1970 but I want it to put it without a year in the address book if that's at all possible.

Anyone knows?

有帮助吗?

解决方案

I'm afraid thats not possible. Just use the current year or the unix reference date, so you'll have at least the day and month right.

其他提示

You can set a birthdate to a contact (through the Contacts app) with only a month/day. The year is then set to 1604, it's just not shown. If before you do your ABRecordSetValue(), you set the year to 1604, the birthdate will show as just "May 5" when viewing the contact in the Contacts app. It appears as though this is the way Apple specifies 'no year'. You will have to manually check the date later if you plan on showing it otherwise you will display the 1604 year.

You can do this by setting the year of the birthday to 1604, and this will only work with the Gregorian calendar.

See this question and answer for more info.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top