Permalink
Browse files

[ios] pickContact method support for iOS

  • Loading branch information...
1 parent 0906349 commit 089e9e6f60dff810ab680421254b07b35119299d @sgrebnov committed Mar 4, 2014
Showing with 32 additions and 0 deletions.
  1. +9 −0 src/ios/CDVContacts.h
  2. +23 −0 src/ios/CDVContacts.m
@@ -64,6 +64,15 @@
- (void)newPersonViewController:(ABNewPersonViewController*)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person;
- (BOOL)personViewController:(ABPersonViewController*)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person
property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue;
+/*
+ * Launches the Contact Picker to select a single contact.
+ *
+ * arguments:
+ * 1: this is the javascript function that will be called with the contact data as a JSON object (as the first param)
+ * options:
+ * desiredFields: ContactFields array to be returned back
+ */
+- (void)pickContact:(CDVInvokedUrlCommand*)command;
/*
* search - searches for contacts. Only person records are currently supported.
View
@@ -211,6 +211,29 @@ - (void)chooseContact:(CDVInvokedUrlCommand*)command
}
}
+- (void)pickContact:(CDVInvokedUrlCommand *)command
+{
+ // mimic chooseContact method call with required for us parameters
+ NSArray* desiredFields = [command.arguments objectAtIndex:0 withDefault:[NSNull null]];
+ if (desiredFields == nil || desiredFields.count == 0) {
+ desiredFields = [NSArray arrayWithObjects:@"*", nil];
+ }
+ NSMutableDictionary* options = [NSMutableDictionary dictionaryWithCapacity:2];
+
+ [options setObject: desiredFields forKey:@"fields"];
+ [options setObject: [NSNumber numberWithBool: FALSE] forKey:@"allowsEditing"];
+
+ NSArray* args = [NSArray arrayWithObjects:options, nil];
+
+ CDVInvokedUrlCommand* newCommand = [[CDVInvokedUrlCommand alloc] initWithArguments:args
+ callbackId:command.callbackId
+ className:command.className
+ methodName:command.methodName];
+
+ [self chooseContact:newCommand];
+
+}
+
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{

0 comments on commit 089e9e6

Please sign in to comment.