Skip to content

Commit

Permalink
chore(ios): support new property to remove note
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysingh-axway committed Sep 27, 2019
1 parent 1a47522 commit abeb567
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions iphone/Classes/ContactsModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@private
BOOL reloadAddressBook;
BOOL animated;
BOOL _includeNote;
KrollCallback *cancelCallback;
KrollCallback *selectedPersonCallback;
KrollCallback *selectedPropertyCallback;
Expand Down
24 changes: 21 additions & 3 deletions iphone/Classes/ContactsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (void)startup
{
[super startup];
contactStore = NULL;
_includeNote = YES;
}

//used for fetch predicates.
Expand Down Expand Up @@ -103,6 +104,11 @@ - (NSString *)apiName

#pragma mark Public API

- (void)setIncludeNote:(id)arg
{
_includeNote = [TiUtils boolValue:arg def:YES];
}

- (NSNumber *)hasContactsPermissions:(id)unused
{
NSString *calendarPermission = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSContactsUsageDescription"];
Expand Down Expand Up @@ -271,7 +277,11 @@ - (TiContactsPerson *)getPersonByIdentifier:(id)arg
}
NSError *error = nil;
CNContact *contact = nil;
contact = [ourContactStore unifiedContactWithIdentifier:arg keysToFetch:[ContactsModule contactKeysWithImage] error:&error];
NSMutableArray *contactKeys = [NSMutableArray arrayWithArray:[ContactsModule contactKeysWithImage]];
if (!_includeNote) {
[contactKeys removeObject:CNContactNoteKey];
}
contact = [ourContactStore unifiedContactWithIdentifier:arg keysToFetch:contactKeys error:&error];
if (error) {
return nil;
}
Expand Down Expand Up @@ -327,8 +337,12 @@ - (NSArray *)getPeopleWithName:(id)arg
}
NSError *error = nil;
NSArray *contacts = nil;
NSMutableArray *contactKeys = [NSMutableArray arrayWithArray:[ContactsModule contactKeysWithImage]];
if (!_includeNote) {
[contactKeys removeObject:CNContactNoteKey];
}
//returns empty array or nil if there's an error
contacts = [ourContactStore unifiedContactsMatchingPredicate:[CNContact predicateForContactsMatchingName:arg] keysToFetch:[ContactsModule contactKeysWithImage] error:&error];
contacts = [ourContactStore unifiedContactsMatchingPredicate:[CNContact predicateForContactsMatchingName:arg] keysToFetch:contactKeys error:&error];
if (!contacts) {
return nil;
}
Expand Down Expand Up @@ -365,7 +379,11 @@ - (NSArray *)getAllPeople:(id)unused
NSMutableArray *peopleRefs = nil;
peopleRefs = [[NSMutableArray alloc] init];
//this fetch request takes all information. Not advised to use this method if addressbook is huge. May result in performance issues.
CNContactFetchRequest *fetchRequest = [[CNContactFetchRequest alloc] initWithKeysToFetch:[ContactsModule contactKeysWithImage]];
NSMutableArray *array = [NSMutableArray arrayWithArray:[ContactsModule contactKeysWithImage]];
if (!_includeNote) {
[array removeObject:CNContactNoteKey];
}
CNContactFetchRequest *fetchRequest = [[CNContactFetchRequest alloc] initWithKeysToFetch:array];
BOOL success = [ourContactStore enumerateContactsWithFetchRequest:fetchRequest
error:&error
usingBlock:^(CNContact *__nonnull contact, BOOL *__nonnull stop) {
Expand Down

0 comments on commit abeb567

Please sign in to comment.