IOS怎样使用MessageUI Framework 发送短信息
操作方法
- 01
在iOS学习中使用MessageUI Framework 发送短信息是一个比较难的技术。本篇将专门讲述IOS怎样使用MessageUI Framework 发送短信息。使用MessageUI Framework 中的 MFMessageComposeViewController 发送短信息,另外其中的MFMailComposeViewController用于发送邮件。使用非常简单:1. 导入框架:MessageUI.framework2. 添加协议:<MFMessageComposeViewControllerDelegate>3. #import <MessageUI/MessageUI.h> 1 //判断当前设备是否可以发送短信息2 if([MFMessageComposeViewController canSendText])3 {45 MFMessageComposeViewController *mc = [[MFMessageComposeViewController alloc] init];6 //设置委托7 mc.messageComposeDelegate = self;8 //短信内容9 mc.body = @"nihao";10 //短信接收者,可设置多个11 mc.recipients = [NSArray arrayWithObject:@"10086",nil];12 13 [self presentModalViewController:mc animated:YES];14 [mc release];15 }16 else17 {18 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error",19 message:@"The current device can not send SMS"20 delegate:nil21 cancelButtonTitle:"OK",22 otherButtonTitles:nil];23 [alert show];24 [alert release];25 }262728 #pragma mark -29 #pragma mark MFMessageComposeViewControllerDelegate30 -(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result31 {32 switch(result)33 {34 case MessageComposeResultCancelled:35 ...36 case MessageComposeResultFailed:37 ...38 case MessageComposeResultSend:39 ... 40 default:41 ...42 }43 }