Cordova联系人选择器插件调用

时间:2014-07-09 20:23:27

标签: ios objective-c cordova contacts

我使用以下插件从我的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

谢谢。

1 个答案:

答案 0 :(得分:2)

现在在版本1.0.4中修复了该错误

https://github.com/kolwit/com.kolwit.pickcontact/tree/v1.0.4