incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [12/29] ios commit: Updating contacts for unified JS
Date Fri, 16 Mar 2012 18:14:49 GMT
Updating contacts for unified JS

*Removed calling back to cast methods
*Modified argument passing into search - fields array is in arguments,
Contact object is the only entry in options
*Modified remove to take Contact id as input, no longer returns removed Contact


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/9559aacd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/9559aacd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/9559aacd

Branch: refs/heads/master
Commit: 9559aacdb83c3ac8853391b187dc572aa3a15aee
Parents: 9bf0e8c
Author: Becky Gibson <becka11y@apache.org>
Authored: Tue Mar 13 09:30:01 2012 -0400
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Fri Mar 16 10:56:50 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVContact.h  |    2 +-
 CordovaLib/Classes/CDVContact.m  |   14 +++++++-------
 CordovaLib/Classes/CDVContacts.m |   27 ++++++++++++++-------------
 3 files changed, 22 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/9559aacd/CordovaLib/Classes/CDVContact.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContact.h b/CordovaLib/Classes/CDVContact.h
index d392af6..63c7fbb 100644
--- a/CordovaLib/Classes/CDVContact.h
+++ b/CordovaLib/Classes/CDVContact.h
@@ -27,7 +27,7 @@ enum CDVContactError {
 	UNKNOWN_ERROR = 0,
 	INVALID_ARGUMENT_ERROR = 1,
 	TIMEOUT_ERROR = 2,
-	PENDING_OPERATION_ERROR = 2,
+	PENDING_OPERATION_ERROR = 3,
 	IO_ERROR = 4,
 	NOT_SUPPORTED_ERROR = 5,
 	PERMISSION_DENIED_ERROR = 20

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/9559aacd/CordovaLib/Classes/CDVContact.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContact.m b/CordovaLib/Classes/CDVContact.m
index cd76f81..9640569 100644
--- a/CordovaLib/Classes/CDVContact.m
+++ b/CordovaLib/Classes/CDVContact.m
@@ -283,19 +283,19 @@ static NSDictionary*	org_apache_cordova_contacts_defaultFields = nil;
 	// set phoneNumbers
 	//NSLog(@"setting phoneNumbers");
 	NSArray* array = [aContact valueForKey:kW3ContactPhoneNumbers];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		[self setMultiValueStrings: array forProperty: kABPersonPhoneProperty inRecord: person
asUpdate: bUpdate];
 	}
 	// set Emails
 	//NSLog(@"setting emails");
 	array = [aContact valueForKey:kW3ContactEmails];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		[self setMultiValueStrings: array forProperty: kABPersonEmailProperty inRecord: person
asUpdate: bUpdate];
 	}
 	// set Urls
 	//NSLog(@"setting urls");
 	array = [aContact valueForKey:kW3ContactUrls];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		[self setMultiValueStrings: array forProperty: kABPersonURLProperty inRecord: person asUpdate:
bUpdate];
 	}
 	
@@ -306,13 +306,13 @@ static NSDictionary*	org_apache_cordova_contacts_defaultFields = nil;
 	//NSLog(@"setting addresses");
 	error = nil;
 	array = [aContact valueForKey:kW3ContactAddresses];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		[self setMultiValueDictionary: array forProperty: kABPersonAddressProperty inRecord: person
asUpdate: bUpdate];
 	}
 	//ims
 	//NSLog(@"setting ims");
 	array = [aContact valueForKey:kW3ContactIms];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		[self setMultiValueDictionary: array forProperty: kABPersonInstantMessageProperty inRecord:
person asUpdate: bUpdate];
 	}
 	
@@ -321,7 +321,7 @@ static NSDictionary*	org_apache_cordova_contacts_defaultFields = nil;
 	// iOS only supports name, title, department
 	//NSLog(@"setting organizations");
 	array = [aContact valueForKey:kW3ContactOrganizations];  // iOS only supports one organization
- use first one
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		NSDictionary* dict = [array objectAtIndex:0];
 		if ([dict isKindOfClass:[NSDictionary class]]){
 			[self setValue: [dict valueForKey:@"name"] forProperty: kABPersonOrganizationProperty
inRecord: person asUpdate: bUpdate];
@@ -360,7 +360,7 @@ static NSDictionary*	org_apache_cordova_contacts_defaultFields = nil;
 	
 	// photo
 	array = [aContact valueForKey: kW3ContactPhotos];
-	if ([array isKindOfClass:[NSArray class]]){
+	if ([array isKindOfClass:[NSArray class]] && [array count] > 0){
 		if (bUpdate && [array count] == 0){
 			// remove photo
 			bSuccess = ABPersonRemoveImageData(person, &error);

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/9559aacd/CordovaLib/Classes/CDVContacts.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContacts.m b/CordovaLib/Classes/CDVContacts.m
index cf38542..8c397a5 100755
--- a/CordovaLib/Classes/CDVContacts.m
+++ b/CordovaLib/Classes/CDVContacts.m
@@ -247,12 +247,11 @@
 	NSString* callbackId = [arguments objectAtIndex:0];
 	
 	
-	NSArray* fields = [options valueForKey:@"fields"];
-	NSDictionary* findOptions = [options valueForKey:@"findOptions"];
-	
+	//NSArray* fields = [options valueForKey:@"fields"];
+    NSArray* fields = [arguments objectAtIndex:1];
+	NSDictionary* findOptions = options;
 	ABAddressBookRef  addrBook = nil;
 	NSArray* foundRecords = nil;
-	
 
 	addrBook = ABAddressBookCreate();
 	// get the findOptions values
@@ -320,7 +319,7 @@
 	}
 	CDVPluginResult* result = nil;
     // return found contacts (array is empty if no contacts found)
-    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray: returnContacts
 cast: @"navigator.contacts._findCallback"];
+    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray: returnContacts];
     jsString = [result toSuccessCallbackString:callbackId];
     // NSLog(@"findCallback string: %@", jsString);
 	
@@ -349,7 +348,7 @@
 	CFErrorRef error;
 	CDVPluginResult* result = nil;	
 	
-	NSMutableDictionary* contactDict = [options valueForKey:@"contact"];
+	NSMutableDictionary* contactDict = options; //[options valueForKey:@"contact"];
 	
 	ABAddressBookRef addrBook = ABAddressBookCreate();	
 	NSNumber* cId = [contactDict valueForKey:kW3ContactId];
@@ -384,7 +383,7 @@
 			// for now (while testing) give back saved, full contact
 			NSDictionary* newContact = [aContact toDictionary: [CDVContact defaultFields]];
 			//NSString* contactStr = [newContact JSONRepresentation];
-			result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: newContact
cast: @"navigator.contacts._contactCallback" ];
+			result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: newContact];
 			jsString = [result toSuccessCallbackString:callbackId];
 		}
 	} else {
@@ -395,7 +394,7 @@
 	CFRelease(addrBook);
 		
 	if (bIsError){
-		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt: errCode
cast:@"navigator.contacts._errCallback" ];
+		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:
errCode];
 		jsString = [result toErrorCallbackString:callbackId];
 	}
 	
@@ -409,6 +408,7 @@
 - (void) remove: (NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
 {
 	NSString* callbackId = [arguments objectAtIndex:0];
+    NSNumber* cId = [arguments objectAtIndex:1];
 	NSString* jsString = nil;
 	bool bIsError = FALSE, bSuccess = FALSE;
 	CDVContactError errCode = UNKNOWN_ERROR;
@@ -417,9 +417,9 @@
 	ABRecordRef rec = nil;
 	CDVPluginResult* result = nil;
 	
-	NSMutableDictionary* contactDict = [options valueForKey:@"contact"];
+	//NSMutableDictionary* contactDict = options;
 	addrBook = ABAddressBookCreate();	
-	NSNumber* cId = [contactDict valueForKey:kW3ContactId];
+	//NSNumber* cId = [contactDict valueForKey:kW3ContactId];
 	if (cId && ![cId isKindOfClass:[NSNull class]] && [cId intValue] != kABRecordInvalidID){
 		rec = ABAddressBookGetPersonWithRecordID(addrBook, [cId intValue]);
 		if (rec){
@@ -434,8 +434,9 @@
 					errCode = IO_ERROR;
 				}else {
 					// set id to null
-					[contactDict setObject:[NSNull null] forKey:kW3ContactId];
-					result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:
contactDict cast: @"navigator.contacts._contactCallback"];
+					//[contactDict setObject:[NSNull null] forKey:kW3ContactId];
+                    //result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:
contactDict];
+                    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
 					jsString = [result toSuccessCallbackString:callbackId];
 					//NSString* contactStr = [contactDict JSONRepresentation];
 				}
@@ -457,7 +458,7 @@
 		CFRelease(addrBook);
 	}
 	if (bIsError){
-		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt: errCode
cast: @"navigator.contacts._errCallback"];
+		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageToErrorObject:
errCode];
 		 jsString = [result toErrorCallbackString:callbackId];
 	}
 	if (jsString){


Mime
View raw message