方法一:
//在iPhone中,可以直接用UIApp打开URL地址。如下所示: [ UIApp openURL: [ NSURL URLWithString:@"http://www.apple.com" ] ]; //或者: [ UIApp openURL: [ NSURL URLWithString:@"mailto:[email protected]?Subject=hello" ] ]; //与此同时,iPhone还包含一些其他除了http://或者mailto:之外的URL: sms:// 可以调用短信程序 tel:// 可以拨打电话 itms:// 可以打开MobileStore.app audio-player-event:// 可以打开iPod audio-player-event://?uicmd=show-purchased-playlist 可以打开iPod播放列表 video-player-event:// 可以打开iPod中的视频
电话,短信,邮件功能可用以下方法
方法二:
电话
NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", PhoneNumber]; NSLog(@"call phone %@;", mobileNumber); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];
引入头文件 #import <MessageUI/MFMailComposeViewController.h>
//发邮箱 Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if (mailClass != nil) { // We must always check whether the current device is configured for sending emails if ([mailClass canSendMail]) { [self displayMailComposerSheet:MailNumber]; } else { [self launchMailAppOnDevice]; } } else { [self launchMailAppOnDevice]; }
//---------------------------------- -(void)displayMailComposerSheet:(NSString *)strMail { NSLog(@"displayMailComposerSheet"); if (_Emailpicker == nil) { _Emailpicker = [[MFMailComposeViewController alloc] init]; _Emailpicker.mailComposeDelegate = self; [_Emailpicker setSubject:@""]; } // Set up recipients NSArray *toRecipients = [NSArray arrayWithObject:strMail]; [_Emailpicker setToRecipients:toRecipients]; [_Emailpicker setMessageBody:@"" isHTML:NO];[self presentModalViewController:Emailpicker animated:YES]; } -(void)launchMailAppOnDevice { MyLog(@"launchMailAppOnDevice"); } // Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.//发送完邮件
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {[controller dismissModalViewControllerAnimated:NO];//邮件视图下拉消失}短信:(使用MFMessageComposeViewController )
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController")); NSLog(@"can send SMS [%d]", [messageClass canSendText]); if (messageClass != nil) { if ([messageClass canSendText]) { [self displayMessageComposerSheet:MsmNumber]; } else { [self launchMessageAppOnDevice];//设备没有短信功能 } } else { [self launchMessageAppOnDevice];//iOS版本过低,iOS4.0以上才支持程序内发送短信 }
-(void)displayMessageComposerSheet:(NSString *)strMail { MyLog(@"displayMessageComposerSheet"); MFMessageComposeViewController *messagePicker = [[MFMessageComposeViewController alloc] init]; messagePicker.messageComposeDelegate = self; messagePicker.body = @""; [self presentModalViewController:messagePicker animated:YES]; // [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:_Emailpicker animated:YES]; [messagePicker release]; } -(void)launchMessageAppOnDevice { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"此设备不支持发送短信或系统版本过低" delegate:nil cancelButtonTitle:@"确定 " otherButtonTitles:nil, nil]; [alert show]; [alert release]; } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [controller dismissModalViewControllerAnimated:NO]; }