iPhone联系人周年纪念日 [英] Anniversary from contacts in iPhone

查看:132
本文介绍了iPhone联系人周年纪念日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从联系人那里获得出生日期,但不能在iPhone上获取周年纪念日。我使用过KABPersonAnniversaryLabel,但是它出错。

I'm able to get birth dates from contacts but not the anniversary dates on iPhone. I have used KABPersonAnniversaryLabel but it is giving an error.

推荐答案

此代码将为所有联系人提取周年纪念日,

This code will fetch anniversary for all contacts,

    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
    for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
        ABRecordRef person = CFArrayGetValueAtIndex(people, i);
        ABMultiValueRef anniversaries = ABRecordCopyValue(person, kABPersonDateProperty);
        NSString *anniversaryLabel;
        for (CFIndex j=0; j < ABMultiValueGetCount(anniversaries); j++) {
            anniversaryLabel = (NSString*)ABMultiValueCopyLabelAtIndex(anniversaries, j);
            if([anniversaryLabel isEqualToString:(NSString *)kABPersonAnniversaryLabel])
            {
                NSDate *anniversaryDate=(NSDate *)ABMultiValueCopyValueAtIndex(anniversaries, j);
                NSLog(@"%@",anniversaryDate);
            }
        }
        CFRelease(anniversaries);
    }
    CFRelease(addressBook);
    CFRelease(people);

这篇关于iPhone联系人周年纪念日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆