2012-10-21 55 views

回答

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:[email protected]?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]; 
} 
相關問題