Closed kennyszub closed 8 years ago
Can you, please, share the code of APAddressBook setup and contacts loading?
I was just doing this:
APAddressBook addressBook = [[APAddressBook alloc] init]; addressBook.filterBlock = ^BOOL(APContact contact) { return contact.addresses.count > 0; }; [addressBook loadContacts:^(NSArray contacts, NSError error) { if (!error) { // contacts array was always empty for me } else { // was not encountering any NSError } }];
And I would get an empty array, despite many of my contacts having addresses. When I set a breakpoint in the filter block, I saw other attributes on APContact properly set, but addresses was nil even if the contact had addresses.
I was able get addresses no problem when I just used the core foundation frameworks directly, so I'm fairly certain there's an issue.
You should set fieldMask
with contact's properties that your app need.
Example:
...
addressBook.fieldsMask = APContactFieldFirstName | APContactFieldLastName | APContactFieldAddresses
...
It still continues on my project, the contacts array in debug mode: contacts __NSArrayI * @"320 objects" 0x173a5200 [0] APContact * 0 key/value pairs 0x1665e790 [1] APContact * 0 key/value pairs 0x1665e710 [2] APContact * 0 key/value pairs 0x1665e6c0 ...
My code:
APAddressBook *addressBook = [[APAddressBook alloc] init];
addressBook.fieldsMask = APContactFieldFirstName | APContactFieldLastName | APContactFieldPhones | APContactFieldThumbnail;
[addressBook loadContacts:^(NSArray *contacts, NSError *error)
{
if (!error)
{
//NSLog ...
}
else
{
// show error
}
}];
1) Does Example
app work correct on your device/simulator?
2) Do you try to put breakpoint in APContact
initialization method?
Yes Example App
worked on phones (4s & 6). I didn't fully understand what happened but it works know.
In the first place, I wasn't assign the result array parameters to APContact
. So the problem occurs about that I guess.
Thanks @belkevich
You are welcome!
Whether a contact has an address or not, I'm always seeing an empty addresses array in the filterBlock.