Alterplay / APAddressBook

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

Can you tell me what is wrong? #102

Closed eduardobonfa closed 9 years ago

eduardobonfa commented 9 years ago
- (void)reloadContacts {
        APAddressBook *addressBook = [[APAddressBook alloc] init];
        returnContact = [[NSMutableArray alloc] init];

        addressBook.fieldsMask = APContactFieldDefault;
        addressBook.sortDescriptors = @[
                                        [NSSortDescriptor sortDescriptorWithKey:@"name.firstName" ascending:YES],
                                        [NSSortDescriptor sortDescriptorWithKey:@"name.lastName" ascending:YES]
                                        ];
        addressBook.filterBlock = ^BOOL(APContact *contact)
        {
            return contact.phones.count > 0;
        };
        [addressBook loadContacts:^(NSArray <APContact *> *contacts, NSError *error) {
            if (!error) {
                for (int i = 0 ; i < contacts.count; i++) {
                    contactAP = [contacts objectAtIndex:i];
                    ContactData *contactData = [[ContactData alloc] init];
                    contactData.name =  contactAP.name.compositeName;
                    contactData.ID = contactAP.recordID;
                    for (int j = 0; j < contactAP.phones.count; j++) {
                        APPhone *contactPhone = [contactAP.phones objectAtIndex:j];
                        NSString *phoneNumber = contactPhone.number;
                        [contactData.phoneNumbers addObject:phoneNumber];
                    }
                    [returnContact addObject:contactData];
                }
            } else if (error) {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
                                                                    message:error.localizedDescription
                                                                   delegate:nil
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil];
                [alertView show];
            }
        }];
belkevich commented 9 years ago

Sorry, I don't understand what are your trying to do.

eduardobonfa commented 9 years ago

I'm trying to load the contacts and save in a NSMutableArray, but it isn't working.

APContact* contactAP; NSMutableArray* returnContact;

belkevich commented 9 years ago

Ok, so what the problem?

belkevich commented 9 years ago

returnContact is empty or what?

eduardobonfa commented 9 years ago

yes. it is

eduardobonfa commented 9 years ago

i added a break point on this line [addressBook loadContacts:^(NSArray <APContact > contacts, NSError *error) {} and it doesn't go inside

belkevich commented 9 years ago

Sure, it's asynchronous callback. Add breakpoint to the next line