Alterplay / APAddressBook

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

Get contact emails #93

Closed JordanMontel closed 8 years ago

JordanMontel commented 8 years ago

Hello,

Thanks for your library to save me a lot of time :)

When I do the following code :

APAddressBook *addressBook = [[APAddressBook alloc] init];

    [addressBook loadContacts:^(NSArray *contacts, NSError *error) {

        for (APContact *contact in contacts)
        {
            NSLog(@"contact name : %@ - %@", contact.firstName, contact.lastName);
            NSLog(@"%@", contact.emails);
            NSLog(@"%@", contact.phones);
            NSLog(@"\n\n");
        }
    }];

I retrieved all phones numbers per contact but emails are always "null". I tried to test both device and simulator on iOS 8 and 9.

The code in APContact never run inside this test :

    if (fieldMask & APContactFieldEmails)
    {
        _emails = [self arrayProperty:kABPersonEmailProperty fromRecord:recordRef];
    }

Thank by advance for your answer.

belkevich commented 8 years ago

Looks like you forget to set fieldMask.

APAddressBook *addressBook = [[APAddressBook alloc] init];
addressBook.fieldsMask = APContactFieldDefault | APContactFieldEmails;

Read Select contact fields bit-mask section of readme;

JordanMontel commented 8 years ago

Thank you it works :)