2014-07-09 34 views
1

我使用下面的插件可供选择我在我的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 

谢谢。

回答

相关问题