MFMessageComposeViewController无法正常工作

我有一个简单的方法,获取一个参数,然后发送一条消息。 它不起作用。

码:

- (void)sendSMS:(NSString *)text { MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init]; viewController.body = text; viewControllerM.mailComposeDelegate = self; [self presentViewController:viewController animated:YES completion:nil]; } 

怎么了?

您需要设置委托:

 MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; if([MFMessageComposeViewController canSendText]) { controller.body = @"YO"; controller.recipients = [NSArray arrayWithObjects:@"5625555555", nil]; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; }