1打电话功能
NSString *str = [telePhone stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSLog(@"telephone:%@",str);//str为电话号码
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",str]]];
2发短信功能引入MessageUI.framework库文件
#import <MessageUI/MessageUI.h>添加这两个协议
MFMessageComposeViewControllerDelegate
#pragma mark ------Send Message------
- (void)sendMessage
{
//message
BOOL canSendSMS = [MFMessageComposeViewController canSendText];
if (canSendSMS) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
//picker.navigationBar.tintColor = [UIColor blackColor];
picker.body = [message objectAtIndex:message_objindex] ;
//picker.recipients = [NSArray arrayWithObject:@"186-0123-0123"];
[self presentModalViewController:picker animated:YES];
[picker release];
}else {
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"没有短信功能" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertDialog show];
}
}
3 获取通讯录
#pragma mark ---------Get Phone List------
- (void)getPhoneList
{
ABAddressBookRef addressBook = nil;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)
{
addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
//等待同意后向下执行
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)
{
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
}
else
{
addressBook = ABAddressBookCreate();
}
NSArray *myContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i = 0; i < [myContactArray count]; i++){
ABRecordRef people = (ABRecordRef)[myContactArray objectAtIndex:i];
CFStringRef firstName = ABRecordCopyValue(people, kABPersonFirstNameProperty);
CFStringRef midName = ABRecordCopyValue(people, kABPersonMiddleNameProperty);
CFStringRef lastName = ABRecordCopyValue(people, kABPersonLastNameProperty);
CFStringRef items = ABRecordCopyValue(people,kABPersonPhoneProperty);
NSMutableString *fullName = [NSMutableString string];
if([(NSString *)lastName length] > 0){
[fullName appendString:(NSString *)lastName];
}
if([(NSString *)firstName length] > 0){
[fullName appendString:(NSString *)firstName];
}
if([(NSString *)midName length] > 0){
[fullName appendString:(NSString *)midName];
}
CFArrayRef phoneNums = ABMultiValueCopyArrayOfAllValues(items);
if (phoneNums) {
for (int j=0; j<CFArrayGetCount(phoneNums); j++)
{
NSString *phone = (NSString*)CFArrayGetValueAtIndex(phoneNums, j);
[name addObject:fullName];
[phonenum addObject:phone];
}
}
}
}
4发邮件
添加这个协议MFMailComposeViewControllerDelegate,
#pragma mark ----- Send Email--------
-(void)displayComposerSheet
{ Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{ // We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"春节快乐!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@" "];
[picker setToRecipients:toRecipients];
[picker setMessageBody:[message objectAtIndex:message_objindex] isHTML:NO];
// Fill out the email body text
[self presentModalViewController:picker animated:YES];
}
else
{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]initWithTitle:@"提醒" message:@"不支持功能" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertDialog show];
} }
}