iOS 在当前控制器中发送短信

- (void)showMessageViewWithTel:(NSString *)tel
{ if( [MFMessageComposeViewController canSendText] ){ MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init]; //autorelease]; controller.recipients = [NSArray arrayWithObject:tel];
controller.body = @"";
controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:@"测试短信"];//修改短信界面标题
}else{ [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
}
} //MFMessageComposeViewControllerDelegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ [controller dismissViewControllerAnimated:NO completion:nil];//关键的一句 不能为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]; }
上一篇:[Angular] Overlay CDK


下一篇:iOS开发之线程间的MachPort通信与子线程中的Notification转发