Update CDVContact and CDVContacts to new exec format.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/151a0f66 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/151a0f66 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/151a0f66 Branch: refs/heads/master Commit: 151a0f66093a61fbd87387eb8ebe93c6bb01ee27 Parents: 886a4fc Author: Andrew Grieve <agri...@chromium.org> Authored: Fri Aug 3 09:56:46 2012 -0400 Committer: Andrew Grieve <agri...@chromium.org> Committed: Fri Aug 3 11:16:58 2012 -0400 ---------------------------------------------------------------------- CordovaLib/Classes/CDVContact.h | 2 +- CordovaLib/Classes/CDVContact.m | 4 +- CordovaLib/Classes/CDVContacts.h | 12 ++++---- CordovaLib/Classes/CDVContacts.m | 44 +++++++++++++++------------------ 4 files changed, 29 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/151a0f66/CordovaLib/Classes/CDVContact.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVContact.h b/CordovaLib/Classes/CDVContact.h index a9a1a08..131180d 100644 --- a/CordovaLib/Classes/CDVContact.h +++ b/CordovaLib/Classes/CDVContact.h @@ -52,7 +52,7 @@ typedef NSUInteger CDVContactError; +(NSDictionary*) calcReturnFields: (NSArray*)fields; -(id)init; -(id)initFromABRecord: (ABRecordRef) aRecord; --(bool) setFromContactDict:(NSMutableDictionary*) aContact asUpdate: (BOOL)bUpdate; +-(bool) setFromContactDict:(NSDictionary*) aContact asUpdate: (BOOL)bUpdate; +(BOOL) needsConversion: (NSString*)W3Label; +(CFStringRef) convertContactTypeToPropertyLabel:(NSString*)label; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/151a0f66/CordovaLib/Classes/CDVContact.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVContact.m b/CordovaLib/Classes/CDVContact.m index 2730cee..88f533a 100644 --- a/CordovaLib/Classes/CDVContact.m +++ b/CordovaLib/Classes/CDVContact.m @@ -207,7 +207,7 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; * may not exist. * bUpdate = YES indicates this is a save of an existing record */ --(bool) setFromContactDict:(NSMutableDictionary*) aContact asUpdate: (BOOL) bUpdate +-(bool) setFromContactDict:(NSDictionary*) aContact asUpdate: (BOOL) bUpdate { if (![aContact isKindOfClass:[NSDictionary class]]){ @@ -221,7 +221,7 @@ static NSDictionary* org_apache_cordova_contacts_defaultFields = nil; // set name info // iOS doesn't have displayName - might have to pull parts from it to create name bool bName = false; - NSMutableDictionary* dict = [aContact valueForKey:kW3ContactName]; + NSDictionary* dict = [aContact valueForKey:kW3ContactName]; if ([dict isKindOfClass:[NSDictionary class]]){ bName = true; NSArray* propArray = [[CDVContact defaultObjectAndProperties] objectForKey: kW3ContactName]; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/151a0f66/CordovaLib/Classes/CDVContacts.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVContacts.h b/CordovaLib/Classes/CDVContacts.h index f494778..c709ab9 100755 --- a/CordovaLib/Classes/CDVContacts.h +++ b/CordovaLib/Classes/CDVContacts.h @@ -39,7 +39,7 @@ * arguments: * 1: successCallback: this is the javascript function that will be called with the newly created contactId */ -- (void) newContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) newContact:(CDVInvokedUrlCommand*)command; /* * displayContact - IN PROGRESS @@ -51,7 +51,7 @@ * options: * allowsEditing: set to true to allow the user to edit the contact - currently not supported */ -- (void) displayContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) displayContact:(CDVInvokedUrlCommand*)command; /* * chooseContact @@ -61,7 +61,7 @@ * options: * allowsEditing: set to true to not choose the contact, but to edit it in the iPhone contact editor */ -- (void) chooseContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) chooseContact:(CDVInvokedUrlCommand*)command; - (void) newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person; - (BOOL) personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person @@ -78,7 +78,7 @@ * findOptions - ContactFindOptions object as dictionary * */ -- (void) search:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) search:(CDVInvokedUrlCommand*)command; /* * save - saves a new contact or updates and existing contact * @@ -87,7 +87,7 @@ * search calls a fixed navigator.service.contacts._findCallback which then calls the succes callback stored before making the call into obj. c * */ -- (void) save:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) save:(CDVInvokedUrlCommand*)command; /* * remove - removes a contact from the address book * @@ -97,7 +97,7 @@ * options: dictionary containing Contact object to remove * contact - Contact object as dictionary */ -- (void) remove: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) remove:(CDVInvokedUrlCommand*)command; //- (void) dealloc; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/151a0f66/CordovaLib/Classes/CDVContacts.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVContacts.m b/CordovaLib/Classes/CDVContacts.m index a47e6f4..2c6ed39 100755 --- a/CordovaLib/Classes/CDVContacts.m +++ b/CordovaLib/Classes/CDVContacts.m @@ -20,6 +20,7 @@ #import "CDVContacts.h" #import <UIKit/UIKit.h> +#import "NSArray+Comparisons.h" #import "NSDictionary+Extensions.h" #import "CDVNotification.h" @@ -70,9 +71,9 @@ // iPhone only method to create a new contact through the GUI -- (void) newContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options; +- (void) newContact:(CDVInvokedUrlCommand*)command { - NSString* callbackId = [arguments objectAtIndex:0]; + NSString* callbackId = command.callbackId; CDVNewContactsController* npController = [[CDVNewContactsController alloc] init]; @@ -116,14 +117,11 @@ } -- (void) displayContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) displayContact:(CDVInvokedUrlCommand*)command { - ABRecordID recordID = kABRecordInvalidID; - NSString* callbackId = [arguments objectAtIndex:0]; - - recordID = [[arguments objectAtIndex:1] intValue]; - - + NSString* callbackId = command.callbackId; + ABRecordID recordID = [[command.arguments objectAtIndex:0] intValue]; + NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:[NSNull null]]; bool bEdit = [options isKindOfClass:[NSNull class]] ? false : [options existsValue:@"true" forKey:@"allowsEditing"]; ABAddressBookRef addrBook = ABAddressBookCreate(); @@ -171,9 +169,10 @@ return YES; } -- (void) chooseContact:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) chooseContact:(CDVInvokedUrlCommand*)command { - NSString* callbackId = [arguments objectAtIndex:0]; + NSString* callbackId = command.callbackId; + NSDictionary* options = [command.arguments objectAtIndex:0 withDefault:[NSNull null]]; CDVContactsPicker* pickerController = [[CDVContactsPicker alloc] init]; pickerController.peoplePickerDelegate = self; @@ -240,15 +239,13 @@ } } -- (void) search:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) search:(CDVInvokedUrlCommand*)command { NSString* jsString = nil; - NSString* callbackId = [arguments objectAtIndex:0]; + NSString* callbackId = command.callbackId; + NSArray* fields = [command.arguments objectAtIndex:0]; + NSDictionary* findOptions = [command.arguments objectAtIndex:1 withDefault:[NSNull null]]; - - //NSArray* fields = [options valueForKey:@"fields"]; - NSArray* fields = [arguments objectAtIndex:1]; - NSDictionary* findOptions = options; ABAddressBookRef addrBook = nil; NSArray* foundRecords = nil; @@ -334,9 +331,10 @@ } -- (void) save:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) save:(CDVInvokedUrlCommand*)command { - NSString* callbackId = [arguments objectAtIndex:0]; + NSString* callbackId = command.callbackId; + NSDictionary* contactDict = [command.arguments objectAtIndex:0]; NSString* jsString = nil; bool bIsError = FALSE, bSuccess = FALSE; BOOL bUpdate = NO; @@ -344,8 +342,6 @@ CFErrorRef error; CDVPluginResult* result = nil; - NSMutableDictionary* contactDict = options; //[options valueForKey:@"contact"]; - ABAddressBookRef addrBook = ABAddressBookCreate(); NSNumber* cId = [contactDict valueForKey:kW3ContactId]; CDVContact* aContact = nil; @@ -400,10 +396,10 @@ } -- (void) remove: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +- (void) remove:(CDVInvokedUrlCommand*)command { - NSString* callbackId = [arguments objectAtIndex:0]; - NSNumber* cId = [arguments objectAtIndex:1]; + NSString* callbackId = command.callbackId; + NSNumber* cId = [command.arguments objectAtIndex:0]; NSString* jsString = nil; bool bIsError = FALSE, bSuccess = FALSE; CDVContactError errCode = UNKNOWN_ERROR;