0

我有一个ABPeoplePickerNavigationController,我想从联系人页面(看图片)添加一个返回按钮到联系人列表。

在此处输入图像描述

我找到并修复了它 - 任何需要的人的答案都在我的答案中的代码中。

4

1 回答 1

0
- (void)inviteFromAddresBook{

    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;

    // Display only a person's phone, email, and birthdate
    NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],
                               [NSNumber numberWithInt:kABPersonEmailProperty], nil];


    picker.displayedProperties = displayedItems;
    // Show the picker
    [self presentModalViewController:picker animated:YES];

}

#pragma mark ABPeoplePickerNavigationControllerDelegate methods
// Displays the information of a selected person
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{


    return YES;
}


// Does not allow users to perform default actions such as dialing a phone number, when they select a person property.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    if (property == kABPersonPhoneProperty) {
        ABMultiValueRef phone = ABRecordCopyValue(person, property);
        CFStringRef selectedNumber = ABMultiValueCopyValueAtIndex(phone, identifier);

        //NSLog(@"selected Number: %@",selectedNumber);

        smsPicker = [[MFMessageComposeViewController alloc] init];
        smsPicker.messageComposeDelegate = self;
        smsPicker.recipients = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",selectedNumber], nil];
        smsPicker.body = globalParams.inviteSMS;
        [[smsPicker navigationBar]setBackgroundImage:[UIImage imageNamed:@"Nav_clean"] forBarMetrics:UIBarMetricsDefault];

        [smsPicker.navigationController setDelegate:self];
    }
    else if(property == kABPersonEmailProperty){
        ABMultiValueRef email = ABRecordCopyValue(person, property);
        CFStringRef emailAddress = ABMultiValueCopyValueAtIndex(email, identifier);

        NSString *urlString = mailto:a@a.com?subject=New&body=TestNew;
        NSURL *mailURL = [NSURL URLWithString: urlString];
        [[UIApplication sharedApplication] openURL: mailURL];
    }

    [self dismissModalViewControllerAnimated:YES];
    return NO;
}


// Dismisses the people picker and shows the application when users tap Cancel.
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;{
    [self dismissModalViewControllerAnimated:YES];
}
于 2012-10-21T17:15:43.513 回答