My application ties into the Addressbook framework for iOS, and I'm grabbing contact information.
- firstname
- lastname
- company name
- home email
- work email
- home phone
- work phone
- cell phone
I need to expand on what information I'm grabbing. The issue I'm having in the app, is that it imports the contacts into the users database on the app. When this happens, if I have more than one home email(or any other email/phone field) then it imports two users.
Here is my Person model
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
@interface Person : NSObject
@property (nonatomic, strong) NSString *firstName;
@property (nonatomic, strong) NSString *lastName;
@property (nonatomic, strong) NSString *fullName;
@property (nonatomic, strong) NSString *homeEmail;
@property (nonatomic, strong) NSString *workEmail;
@property (nonatomic, strong) NSString *companyName;
@property (nonatomic, strong) NSString *homePhone;
@property (nonatomic, strong) NSString *workPhone;
@property (nonatomic, strong) NSString *cellPhone;
@property (nonatomic, strong) NSString *sortByName; // Used only for sorting
@property (nonatomic) ABRecordID publicContactRecordId;
@property (nonatomic) NSString *parseObjectId;
- (NSComparisonResult)compareFirstName:(Person *)otherObject;
@end
I guess maybe I should have them as a Dictionary or an Array? The issue is right now, obviously I can't have more than one home email and any other field.
This may provide some more insight,
I'm saving
EDIT:
Here is how I'm retrieving the email and phone numbers from the address book api.
//email
ABMultiValueRef emails = ABRecordCopyValue(contactPerson,
kABPersonEmailProperty);
NSUInteger j = 0;
for (j = 0; j < ABMultiValueGetCount(emails); j++){
NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emails, j);
if (j == 0){
if(email){
person.homeEmail = email;
}
}
else if (j==1){
if(email){
person.workEmail = email;
}
}
}
ABMultiValueRef numbers = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(numbers); i++) {
NSString *phoneLabel = (__bridge NSString *)ABMultiValueCopyLabelAtIndex(numbers, i);
NSString *phoneNumber = (__bridge NSString *)ABMultiValueCopyValueAtIndex(numbers, i);
//NSLog(@"%@ | %@",phoneLabel,phoneNumber);
if([phoneLabel isEqualToString:@"Home Phone"])
{
person.homePhone = phoneNumber;
}else if([phoneLabel isEqualToString:@"Work Phone"])
{
person.workPhone = phoneNumber;
}else if([phoneLabel isEqualToString:@"Cell Phone"])
{
person.cellPhone = phoneNumber;
}
}