Alterplay / APAddressBook

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

Question about fetching contact's image #118

Closed mbayona closed 8 years ago

mbayona commented 8 years ago

I have downloaded APAdressBook and have been able to test it in one of my projects. After following the instructions in the ReadMe file, I am now able to fetch name, and phone number. However, the email, company and image fields do not work: I am testing using:

        NSLog(@"name is : %@, %@",contacts[0].name.firstName,contacts[0].name.lastName);
        NSLog(@"company is : %@",contacts[0].job.company ?: @"No company");
        NSLog(@"email is : %@",contacts[0].emails[0].address ?: @"No email provided");
        NSLog(@"phone is : %@",contacts[0].phones[0].number ?: @"No phone # provided");
        NSLog(@"image is : %@",contacts[0].thumbnail);

Anybody knows how to accomplish these simple tasks...?

(sorry about the redundancy with my previous post...)

Miguel Bayona

belkevich commented 8 years ago

Do you set APContactFieldEmailsOnly (or APContactFieldEmailsWithLabels), APContactFieldJob, APContactFieldThumbnail to fieldMask?

mbayona commented 8 years ago

Alexey,

Thanks for your reply,

the following is the code I am using in the viewDidLoad of a generic viewController. I am sending all info to the console for testing purposes.

APAddressBook *addressBook = [[APAddressBook alloc] init];
self.addressBook.fieldsMask = APContactFieldAll;
// don't forget to show some activity
[addressBook loadContacts:^(NSArray <APContact *> *contacts, NSError *error)
{
    // hide activity
    if (!error)
    {
        // do something with contacts array
       NSLog(@"!!!!!! contact Array count is %li",contacts.count);
       NSLog(@"name is : %@, %@",contacts[0].name.firstName,contacts[0].name.lastName);
       NSLog(@"company is : %@",contacts[0].job.company ?: @"No company");
       NSLog(@"email is : %@",contacts[0].emails[0].address ?: @"No email provided");
       //NSLog(@"phone is : %@",contacts[0].phones[0].number ?: @"No phone # provided");
       NSLog(@"image is : %@",contacts[0].thumbnail);
       UIImage *contactImage1 = contacts[1].thumbnail ?: [UIImage imageNamed:@"ggb.png"];
       //UIImage *contactImage1 = [UIImage imageWithData:(NSData*)contacts[0].thumbnail];
       //_imageTest.image = contactImage1;
       self.imageTest.image = contactImage1;
    }
    else
    {
        // show error
    }
}

Thanks for your help...

Miguel

On Wed, Jan 20, 2016 at 8:16 AM, Alexey Belkevich notifications@github.com wrote:

Do you set APContactFieldEmailsOnly (or APContactFieldEmailsWithLabels), APContactFieldJob, APContactFieldThumbnail to fieldMask?

— Reply to this email directly or view it on GitHub https://github.com/Alterplay/APAddressBook/issues/118#issuecomment-173199817 .

belkevich commented 8 years ago

Please, try Example app. Does it work correct on your device?

mbayona commented 8 years ago

Alexey,

Yes, the sample app works fine, importing all info, images, etc.

What are the 'must-have' imports needed?

Miguel

Sent from my iPhone

On Jan 20, 2016, at 11:25 AM, Alexey Belkevich notifications@github.com wrote:

Please, try Example app. Does it work correct on your device?

— Reply to this email directly or view it on GitHub.

belkevich commented 8 years ago

1) If you missed some required import project wouldn't build. Or may be I don't understand your question? 2) So, may be your first contact in contacts array doesn't have thumbnail? Let's add filter block to filter contacts without thumbnails.

addressBook.filterBlock = ^BOOL(APContact *contact)
{
    return contact.thumbnail != nil;
};
mbayona commented 8 years ago

Alexey,

the following images show what I have, and the behavior I see. Your Sample project runs perfectly, showing the images that the contacts have and all their info. All I want is to implement my own TableView with output similar to yours. As a preliminary test, I like to see that I have all the info I will need to populate the tableCells.

I have a simple View Controller with an image view in it. That's it. I want to see the contact's picture in that view, so I have all connected accordingly. All other fields and arrays I would like to see in my console before I use them.

Imports:

[image: Inline image 1] Inside the viewDidLoad method I have:

[image: Inline image 2]

The app runs, the image is my default "ggb,png".

The Console shows this:

[image: Inline image 3]

thanks,

Miguel

On Wed, Jan 20, 2016 at 11:57 AM, Alexey Belkevich <notifications@github.com

wrote:

1) If you missed some required import project wouldn't build. Or may be I don't understand your question? 2) So, may be your first contact in contacts array doesn't have thumbnail? Let's add filter block to filter contacts without thumbnails.

addressBook.filterBlock = ^BOOL(APContact *contact) { return contact.thumbnail != nil; };

— Reply to this email directly or view it on GitHub https://github.com/Alterplay/APAddressBook/issues/118#issuecomment-173272218 .

mbayona commented 8 years ago

Dear Alexey,

I am wondering if you got my last email where I included some images...

Miguel

On Wed, Jan 20, 2016 at 1:25 PM, Miguel Bayona mbayona@lawrenceville.org wrote:

Alexey,

the following images show what I have, and the behavior I see. Your Sample project runs perfectly, showing the images that the contacts have and all their info. All I want is to implement my own TableView with output similar to yours. As a preliminary test, I like to see that I have all the info I will need to populate the tableCells.

I have a simple View Controller with an image view in it. That's it. I want to see the contact's picture in that view, so I have all connected accordingly. All other fields and arrays I would like to see in my console before I use them.

Imports:

[image: Inline image 1] Inside the viewDidLoad method I have:

[image: Inline image 2]

The app runs, the image is my default "ggb,png".

The Console shows this:

[image: Inline image 3]

thanks,

Miguel

On Wed, Jan 20, 2016 at 11:57 AM, Alexey Belkevich < notifications@github.com> wrote:

1) If you missed some required import project wouldn't build. Or may be I don't understand your question? 2) So, may be your first contact in contacts array doesn't have thumbnail? Let's add filter block to filter contacts without thumbnails.

addressBook.filterBlock = ^BOOL(APContact *contact) { return contact.thumbnail != nil; };

— Reply to this email directly or view it on GitHub https://github.com/Alterplay/APAddressBook/issues/118#issuecomment-173272218 .

belkevich commented 8 years ago

Sorry, I didn't receive any mail from you.

belkevich commented 8 years ago

Why don't you use code from Example.app?

mbayona commented 8 years ago

Alexey,

I have resolved the issues I had. Your code works very nicely. Thanks for your help.

Miguel Bayona

On Mon, Jan 25, 2016 at 6:23 AM, Alexey Belkevich notifications@github.com wrote:

Why don't you use code from Example.app?

— Reply to this email directly or view it on GitHub https://github.com/Alterplay/APAddressBook/issues/118#issuecomment-174477230 .

belkevich commented 8 years ago

You are welcome.