Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better handling of empty first names #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 37 additions & 34 deletions Pod/Classes/GTContactsPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,45 +134,48 @@ - (void)fetchAllContactsWithCompletionBlock:(void (^)(NSArray *, NSError *))comp
NSArray *allPeople = (__bridge NSArray *)people;
NSMutableArray *formattedPeople = [NSMutableArray arrayWithCapacity:allPeople.count];

for (id object in allPeople) {
GTPerson *person = [[GTPerson alloc] init];
ABRecordRef record = (__bridge ABRecordRef)(object);
if (ABPersonHasImageData(record)) {
CFDataRef data = ABPersonCopyImageDataWithFormat(record,kABPersonImageFormatThumbnail);
person.profileImage = [UIImage imageWithData:(__bridge NSData *)data];
CFRelease(data);
}

id firstName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonFirstNameProperty));
person.firstName = firstName;

id lastName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonLastNameProperty));
person.lastName = lastName;

if (!firstName && !lastName) {
firstName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonOrganizationProperty));
person.firstName = firstName;
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

if (self.pickerStyle == GTContactsPickerStyleSingularEmail) {
[formattedPeople addObjectsFromArray:[self sinGularEmailAddressesForRecord:record
ofPerson:person]];
}
else {
person.emailAddresses = [self emailAddressesForRecord:record];
person.phoneNumbers = [self phoneNumbersForRecord:record];
for (id object in allPeople) {
GTPerson *person = [[GTPerson alloc] init];
ABRecordRef record = (__bridge ABRecordRef)(object);
if (ABPersonHasImageData(record)) {
CFDataRef data = ABPersonCopyImageDataWithFormat(record,kABPersonImageFormatThumbnail);
person.profileImage = [UIImage imageWithData:(__bridge NSData *)data];
CFRelease(data);
}

id firstName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonFirstNameProperty));

id lastName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonLastNameProperty));

if (person.emailAddresses.count > 0) {
person.emailAddress = [person.emailAddresses firstObject];
if (!firstName && !lastName) {
firstName = CFBridgingRelease(ABRecordCopyCompositeName(record));
}

[formattedPeople addObject:person];
person.firstName = firstName;
person.lastName = lastName;

if (self.pickerStyle == GTContactsPickerStyleSingularEmail) {
[formattedPeople addObjectsFromArray:[self sinGularEmailAddressesForRecord:record
ofPerson:person]];
}
else {
person.emailAddresses = [self emailAddressesForRecord:record];
person.phoneNumbers = [self phoneNumbersForRecord:record];

if (person.emailAddresses.count > 0) {
person.emailAddress = [person.emailAddresses firstObject];
}

[formattedPeople addObject:person];
}
}
}

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completionBlock(formattedPeople, nil);
}];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completionBlock(formattedPeople, nil);
}];
});
}
}

Expand Down