incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From becka...@apache.org
Subject [4/4] ios commit: Updated chooseContact implementation for allowEditing
Date Thu, 16 Aug 2012 15:23:22 GMT
Updated chooseContact implementation for allowEditing

Need to get the contact information after any edits to make
sure latest information is being returned.


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

Branch: refs/heads/master
Commit: 4d88bcc12dc483d751115430142fd6ef5173376b
Parents: f4ee4ee
Author: Becky Gibson <becka11y@apache.org>
Authored: Thu Aug 16 11:17:11 2012 -0400
Committer: Becky Gibson <becka11y@apache.org>
Committed: Thu Aug 16 11:19:50 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVContacts.h |    6 +++---
 CordovaLib/Classes/CDVContacts.m |   30 +++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4d88bcc1/CordovaLib/Classes/CDVContacts.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContacts.h b/CordovaLib/Classes/CDVContacts.h
index dc3b774..9868514 100755
--- a/CordovaLib/Classes/CDVContacts.h
+++ b/CordovaLib/Classes/CDVContacts.h
@@ -107,14 +107,14 @@
 {
 	BOOL allowsEditing;
 	NSString* callbackId;
-	NSMutableDictionary *options;
+	NSDictionary *options;
 	NSDictionary *pickedContactDictionary;
 }
 
 @property BOOL allowsEditing;
 @property (copy) NSString* callbackId;
-@property (nonatomic, retain) NSMutableDictionary *options;
-@property (nonatomic, retain) NSDictionary *pickedContactDictionary;
+@property (nonatomic, strong) NSDictionary *options;
+@property (nonatomic, strong) NSDictionary *pickedContactDictionary;
 
 @end
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/4d88bcc1/CordovaLib/Classes/CDVContacts.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVContacts.m b/CordovaLib/Classes/CDVContacts.m
index 93b0e2d..774e7b9 100755
--- a/CordovaLib/Classes/CDVContacts.m
+++ b/CordovaLib/Classes/CDVContacts.m
@@ -179,7 +179,7 @@
 	pickerController.peoplePickerDelegate = self;
 	pickerController.callbackId = callbackId;
 	pickerController.options = options;
-	pickerController.pickedContactDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber
numberWithInt:kABRecordInvalidID], @"id", nil];
+	pickerController.pickedContactDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber
numberWithInt:kABRecordInvalidID], kW3ContactId, nil];
 	pickerController.allowsEditing = (BOOL)[options existsValue:@"true" forKey:@"allowsEditing"];
 	
     if ([self.viewController respondsToSelector:@selector(presentViewController:::)]) {
@@ -194,24 +194,25 @@
 {
 	
 	CDVContactsPicker* picker = (CDVContactsPicker*)peoplePicker;
+    NSNumber* pickedId =  [NSNumber numberWithInt: ABRecordGetRecordID(person)];
 
-	// Retreive pickedContact information
-	CDVContact* pickedContact = [[[CDVContact alloc] initFromABRecord:(ABRecordRef)person] autorelease];
-	NSArray *fields = [picker.options objectForKey:@"fields"] ?: [NSArray arrayWithObjects:@"id",
nil];
-	NSDictionary *returnFields = [[CDVContact class] calcReturnFields: fields];
-	picker.pickedContactDictionary = [pickedContact toDictionary:returnFields];
-	
 	if (picker.allowsEditing) {
 		
 		ABPersonViewController* personController = [[ABPersonViewController alloc] init];
 		personController.displayedPerson = person;
 		personController.personViewDelegate = self;
 		personController.allowsEditing = picker.allowsEditing;
-		
+        // store id so can get info in peoplePickerNavigationControllerDidCancel
+        picker.pickedContactDictionary = [NSDictionary dictionaryWithObjectsAndKeys:pickedId,
kW3ContactId, nil];
 		
 		[peoplePicker pushViewController:personController animated:YES];
 	} else {
-		// return the pickedContact information
+        // Retreive and return pickedContact information
+        CDVContact* pickedContact = [[CDVContact alloc] initFromABRecord:(ABRecordRef)person];
+        NSArray *fields = [picker.options objectForKey:@"fields"];
+        NSDictionary *returnFields = [[CDVContact class] calcReturnFields: fields];
+        picker.pickedContactDictionary = [pickedContact toDictionary:returnFields];
+
 		CDVPluginResult *result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary:
picker.pickedContactDictionary];
 		[self writeJavascript:[result toSuccessCallbackString: picker.callbackId]];
 		
@@ -234,6 +235,17 @@
 {
 	// return contactId or invalid if none picked
 	CDVContactsPicker* picker = (CDVContactsPicker*)peoplePicker;
+    if (picker.allowsEditing) {
+        // get the info after possible edit
+        ABAddressBookRef addrBook = ABAddressBookCreate();
+        ABRecordRef person = ABAddressBookGetPersonWithRecordID(addrBook, [[picker.pickedContactDictionary
objectForKey:kW3ContactId] integerValue]);
+        CDVContact* pickedContact = [[CDVContact alloc] initFromABRecord:(ABRecordRef)person];
+        NSArray *fields = [picker.options objectForKey:@"fields"];
+        NSDictionary *returnFields = [[CDVContact class] calcReturnFields: fields];
+        picker.pickedContactDictionary = [pickedContact toDictionary:returnFields];
+        CFRelease(addrBook);
+
+    }
 	CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:picker.pickedContactDictionary];
 	[self writeJavascript:[result toSuccessCallbackString:picker.callbackId]];
 	


Mime
View raw message