Alterplay / APAddressBook

Easy access to iOS address book
MIT License
1.38k stars 192 forks source link

APContact addresses NSArray is always null #70

Closed kennyszub closed 8 years ago

kennyszub commented 9 years ago

Whether a contact has an address or not, I'm always seeing an empty addresses array in the filterBlock.

Krivoblotsky commented 9 years ago

Can you, please, share the code of APAddressBook setup and contacts loading?

kennyszub commented 9 years ago

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.

belkevich commented 9 years ago

You should set fieldMask with contact's properties that your app need. Example:

...
addressBook.fieldsMask = APContactFieldFirstName | APContactFieldLastName | APContactFieldAddresses
...
aykutersahin commented 8 years ago

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
        }
    }];
belkevich commented 8 years ago

1) Does Example app work correct on your device/simulator? 2) Do you try to put breakpoint in APContact initialization method?

aykutersahin commented 8 years ago

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

belkevich commented 8 years ago

You are welcome!