标签:
打电话:
第一种:利用私有API,appStore不合法
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]]
第二种:UIWebView加载电话,这种是合法的,可以上App Store的
UIWebView*callWebview =[[UIWebView alloc] init]; NSURL *telURL =[NSURL URLWithString:@"tel:10010"]; [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; //记得添加到view上 [self.view addSubview:callWebview];
发信息:
第一种:利用私有API
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"]];//发短信
第二种:系统提供的控制器MFMessageComposeViewController
1.控制器实现MFMessageComposeViewController的代理方法MFMessageComposeViewControllerDelegate
@interface DemoViewController : UIViewController <MFMessageComposeViewControllerDelegate> @end
2、调用MFMessageComposeViewController,同时实现协议MFMessageComposeViewControllerDelegate。
- (void)showMessageView { if( [MFMessageComposeViewController canSendText] ){ MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease]; controller.recipients = [NSArray arrayWithObject:@"10010"]; controller.body = @"测试发短信"; controller.messageComposeDelegate = self; [self presentModalViewController:controller animated:YES]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题 }else{ [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"]; } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ [controller dismissModalViewControllerAnimated:NO];//关键的一句 不能为YES switch ( result ) { case MessageComposeResultCancelled: [self alertWithTitle:@"提示信息" msg:@"发送取消"]; break; case MessageComposeResultFailed:// send failed [self alertWithTitle:@"提示信息" msg:@"发送成功"]; break; case MessageComposeResultSent: [self alertWithTitle:@"提示信息" msg:@"发送失败"]; break; default: break; } } - (void) alertWithTitle:(NSString *)title msg:(NSString *)msg { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alert show]; }
参考:http://blog.csdn.net/xyz_lmn/article/details/8968209
标签:
原文地址:http://www.cnblogs.com/mgy007/p/4215235.html