Reputation: 13
I am using the following plugin to choose a phone number from my contacts in my iOS application: https://github.com/kolwit/com.kolwit.pickcontact
There are two issues:
When I click on a contact, it shows all their information, including emails and addresses. Is there a way to limit it to just phone numbers? Also, when I click on a phone number, it starts to call that number rather than alert the number.
Here is the code:
#import "PickContact.h"
#import <Cordova/CDVAvailability.h>
@implementation PickContact;
@synthesize callbackID;
- (void) chooseContact:(CDVInvokedUrlCommand*)command{
self.callbackID = command.callbackId;
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self.viewController presentViewController:picker animated:YES completion:nil];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
if (kABPersonEmailProperty == property)
{
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
int index = ABMultiValueGetIndexForIdentifier(multi, identifier);
NSString *email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multi, index);
NSString *displayName = (__bridge NSString *)ABRecordCopyCompositeName(person);
ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* phoneNumber = @"";
for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
phoneNumber = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multiPhones, i);
break;
}
}
NSMutableDictionary* contact = [NSMutableDictionary dictionaryWithCapacity:2];
[contact setObject:email forKey: @"emailAddress"];
[contact setObject:displayName forKey: @"displayName"];
[contact setObject:phoneNumber forKey: @"phoneNr"];
[super writeJavascript:[[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:contact] toSuccessCallbackString:self.callbackID]];
[self.viewController dismissViewControllerAnimated:YES completion:nil];
return NO;
}
return YES;
}
- (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
return YES;
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[super writeJavascript:[[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:@"PickContact abort"]
toErrorCallbackString:self.callbackID]];
}
@end
Thank you.
Upvotes: 1
Views: 644
Reputation: 36
The bug is fixed now in version 1.0.4
https://github.com/kolwit/com.kolwit.pickcontact/tree/v1.0.4
Upvotes: 2