我使用以下插件从我的iOS应用程序中的联系人中选择一个电话号码:https://github.com/kolwit/com.kolwit.pickcontact
有两个问题:
当我点击某个联系人时,它会显示所有信息,包括电子邮件和地址。有没有办法将其限制为仅限电话号码?此外,当我点击电话号码时,它会开始拨打该号码而不是提醒号码。
以下是代码:
#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
谢谢。