问题
I have a simple method that gets one argument and then sends a message. It is not working.
Code:
- (void)sendSMS:(NSString *)text {
MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
viewController.body = text;
viewControllerM.mailComposeDelegate = self;
[self presentViewController:viewController animated:YES completion:nil];
}
What's wrong?
回答1:
You need to set the delegate:
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];
}
来源:https://stackoverflow.com/questions/14532747/mfmessagecomposeviewcontroller-not-working