ABAddressBookRef addressBook;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
//等待同意后向下执行
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)
{
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); dispatch_release(sema);
}else{
addressBook = ABAddressBookCreate();
}
NSArray* tmpPeoples = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSLog(@"peoples.count=%d",tmpPeoples.count);