From 1f444711c0ae31a19e72fd7584f903ca32d19c75 Mon Sep 17 00:00:00 2001 From: Yuri Buyanov Date: Fri, 24 Apr 2015 12:55:17 +0300 Subject: [PATCH 1/2] better first name prediction Now, if contact has empty last & first names, fetchAllContactsWithCompletionBlock will use contact composite name instead of (potentially empty) organization name. This will allow handle contacts with e.g. only nickname or middle name. --- Pod/Classes/GTContactsPicker.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/GTContactsPicker.m b/Pod/Classes/GTContactsPicker.m index c8bdf24..c7d3d5f 100644 --- a/Pod/Classes/GTContactsPicker.m +++ b/Pod/Classes/GTContactsPicker.m @@ -144,16 +144,16 @@ - (void)fetchAllContactsWithCompletionBlock:(void (^)(NSArray *, NSError *))comp } 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; + firstName = CFBridgingRelease(ABRecordCopyCompositeName(record)); } - + + person.firstName = firstName; + person.lastName = lastName; + if (self.pickerStyle == GTContactsPickerStyleSingularEmail) { [formattedPeople addObjectsFromArray:[self sinGularEmailAddressesForRecord:record ofPerson:person]]; From b0f684d042251af56f21f4eb1e923f52c8ed41c4 Mon Sep 17 00:00:00 2001 From: Alexey Yachmenev Date: Tue, 28 Jul 2015 16:25:37 +0300 Subject: [PATCH 2/2] Parse address book async --- Pod/Classes/GTContactsPicker.m | 71 ++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/Pod/Classes/GTContactsPicker.m b/Pod/Classes/GTContactsPicker.m index c7d3d5f..de1cca8 100644 --- a/Pod/Classes/GTContactsPicker.m +++ b/Pod/Classes/GTContactsPicker.m @@ -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)); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - id lastName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonLastNameProperty)); - - if (!firstName && !lastName) { - firstName = CFBridgingRelease(ABRecordCopyCompositeName(record)); - } - - 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]; + 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); + }]; + }); } }