Closed eduardobonfa closed 9 years ago
Please, share you code of using of APAddressBook
This is my code
NSMutableArray* returnContacts;
APContact* contact;
- (void)reloadContacts {
APAddressBook *addressBook = [[APAddressBook 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++){
contact = [contacts objectAtIndex:i];
NSDictionary *contactDictionary = @{
@"firstName" : contact.firstName,
@"middleName" : contact.middleName,
@"lastName" : contact.lastName,
@"phones" : contact.phones,
};
}
[returnContacts addObject:contactDictionary];
} else if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
}
Looks like problem is in
@"firstName" : contact.firstName,
@"middleName" : contact.middleName,
@"lastName" : contact.lastName,
@"phones" : contact.phones,
there are no such properties, except phones
. Use contact.name.firstName
etc.
if I try it, I get this error
Property 'firstName' cannot be found in forward class object 'APName'
Add #import <APAddressBook/APName.h>
?
it worked, thank you, sorry I'm new at objective c
It's ok. Have a nice day!
HI, I trying to add firstName and phone number in a dictionary so I can deal with it later. So I did this
NSDictionary *contactDictionary = @{ @"firstName" : contact.firstName, @"middleName" : contact.middleName, @"lastName" : contact.lastName, @"phones" : contact.phones, }; But I get this error: Property 'firstName' not found on object of type 'APContact'. (and it's TRUE)
but When I try putting contact.name.firstName it doesn`t work either.
What can I do?