本文介绍了ABAddressBook获取生日属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从iPhone上的ABAddressBook获取生日属性。我浏览了网络上的一些讨论,并且大多数情况下都建议使用相同的答案,如下所示。但这对我仍然不起作用,所以我想知道我是否还错过了其他事情...。

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.

推荐答案

尝试一下:

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

这篇关于ABAddressBook获取生日属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 05:12