-1

我可以从联系人获取出生日期,但不能从 iPhone 上获取周年日期。我使用了 KABPersonAnniversaryLabel,但它给出了一个错误。

4

1 回答 1

1

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

    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);
于 2013-01-09T12:29:31.403 回答