选择与ABPeoplePickerNavigationController联系的电子邮件会尝试发送电子邮件

时间:2017-09-10 18:43:44

标签: ios objective-c

我使用ABPeoplePickerNavigationController获得了一个Objective C项目来选择联系人的电子邮件地址。

代码是这样的:

-(IBAction)_email_contactsbuttonpushed_orig:(UIButton*)contactsbutton {
[AnalyticsWrapper logEvent:@"share_via_contacts_clicked"];

// ABPeoplePickerNavigationController
_contactPicker = [[ABPeoplePickerNavigationController alloc] init];
_contactPicker.peoplePickerDelegate = self;
_contactPicker.delegate = self;


// Define properties to show when viewing a specific person
_contactPicker.displayedProperties = [NSArray arrayWithObjects:@(kABPersonEmailProperty), nil];

// Style the nav bar
[[QPDrawing shared] paintNavBarInController:_contactPicker];



// showing the picker
if (isIpad) {

    self.peoplePopoverController = [[UIPopoverController alloc] initWithContentViewController:_contactPicker];
    _peoplePopoverController.delegate = self;

    CGRect b = self.homeViewController.view.bounds;
    CGRect b2 = (CGRect){
        b.size.width/2-5,0,
        10,self.homeViewController.headerview.bounds.size.height
    };
    b2 = _emailContactsButton.frame;
    b2.origin.y += self.view.frame.origin.y; // push box down to account for header
    [_peoplePopoverController presentPopoverFromRect:b2
                                              inView:self.homeViewController.view
                            permittedArrowDirections: UIPopoverArrowDirectionAny
                                            animated:YES];
}
else {

    [self.homeViewController presentViewController:_contactPicker animated:YES completion:nil];
} 
}

弹出窗口显示正常,我可以选择联系人。 当我选择联系人时,它会打开联系人详细信息。 但是,当我点击一个电子邮件地址时,它会切换到电子邮件应用程序并正在撰写电子邮件 - 就像我打开了我的联系人应用程序等一样。

peoplePickerNavigationController的回调:didSelectPerson永远不会被调用。

这不是我原来的代码,但是我告诉它使用它来工作。其他开发人员虽然没有参与项目,但我不知道是否进行了更改。我知道PeoplePickerNavigationController有点过时了。

任何帮助将不胜感激。谢谢!

编辑 - 有关委托方法的其他信息:

shouldContinueAfterSelectingPerson:

// Called after a person has been selected by the user.
// Return YES if you want the person to be displayed.
// Return NO  to do nothing (the delegate is responsible for dismissing the peoplePicker).
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {


_addressbookFirstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
_addressbookLastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

// Continue on to the person's details
return YES;
}

shouldContinueAfterSelectingPerson:属性:标识符

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {

if ( property != kABPersonEmailProperty ) {
    return NO;
}

1 个答案:

答案 0 :(得分:0)

如果您希望允许用户选择联系人的电子邮件,并且您希望对该电子邮件执行某些操作,那么您需要实施的唯一代理方法是peoplePickerNavigationController:didSelectPerson:property:identifier:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    if (property == kABPersonEmailProperty) {
        // An email property has been selected on person
        ABMultiValueRef ref = ABRecordCopyValue(person, property);
        CFIndex idx = ABMultiValueGetIndexForIdentifier(ref, identifier);
        NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(ref, idx);
        CFRelease(ref);

        _addressbookFirstName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
        _addressbookLastName = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
    }
}