Permalink
Browse files

[ios] desiredFields support for iOS

  • Loading branch information...
1 parent b149e37 commit 0ddb00260dbf297f055deeb5d9a3e46e05958ff6 @sgrebnov committed Mar 4, 2014
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/ios/CDVContacts.m
View
@@ -313,6 +313,7 @@ - (void)search:(CDVInvokedUrlCommand*)command
// get the findOptions values
BOOL multiple = NO; // default is false
NSString* filter = nil;
+ NSArray* desiredFields = nil;
if (![findOptions isKindOfClass:[NSNull class]]) {
id value = nil;
filter = (NSString*)[findOptions objectForKey:@"filter"];
@@ -322,9 +323,15 @@ - (void)search:(CDVInvokedUrlCommand*)command
multiple = [(NSNumber*)value boolValue];
// NSLog(@"multiple is: %d", multiple);
}
+ desiredFields = [findOptions objectForKey:@"desiredFields"];
+ // return all fields if desired fields are not explicitly defined
+ if (desiredFields == nil || desiredFields.count == 0) {
+ desiredFields = [NSArray arrayWithObjects:@"*", nil];
+ }
}
- NSDictionary* returnFields = [[CDVContact class] calcReturnFields:fields];
+ NSDictionary* searchFields = [[CDVContact class] calcReturnFields:fields];
+ NSDictionary* returnFields = [[CDVContact class] calcReturnFields:desiredFields];
NSMutableArray* matches = nil;
if (!filter || [filter isEqualToString:@""]) {
@@ -351,7 +358,7 @@ - (void)search:(CDVInvokedUrlCommand*)command
for (int j = 0; j < testCount; j++) {
CDVContact* testContact = [[CDVContact alloc] initFromABRecord:(__bridge ABRecordRef)[foundRecords objectAtIndex:j]];
if (testContact) {
- bFound = [testContact foundValue:filter inFields:returnFields];
+ bFound = [testContact foundValue:filter inFields:searchFields];
if (bFound) {
[matches addObject:testContact];
}

0 comments on commit 0ddb002

Please sign in to comment.