As soon as the sms window appears, I cannot make it close again. The cancel button does not work, and the send button will send SMS, but does not close the window.
I looked at many similar questions here, and they all suggest either implementing the messageComposeViewController method or setting messageComposeDelegate for myself, but I did both of these things and still nothing.
Can anyone tell me what I'm doing wrong?
.h file
#import <MessageUI/MFMessageComposeViewController.h> #import <MessageUI/MessageUI.h> @interface ViewController : UIViewController<CLLocationManagerDelegate,MFMessageComposeViewControllerDelegate,UINavigationControllerDelegate>{ CLLocationManager *locationManager; MKMapView *mapView_; }
.m file
- (IBAction)SendTextTapped:(id)sender{ MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; if([MFMessageComposeViewController canSendText]) { controller.body = @"Hello!"; controller.recipients = [NSArray arrayWithObjects:@"123456", nil]; controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; } } - (void)messageComposeViewController:(MFMessageComposeViewController*) controller didFinishWithResult:(MessageComposeResult)result error:(NSError*)error; { NSLog(@"Entered messageComposeController"); switch (result) { case MessageComposeResultSent: NSLog(@"SENT"); [self dismissViewControllerAnimated:YES completion:nil]; break; case MessageComposeResultFailed: NSLog(@"FAILED"); [self dismissViewControllerAnimated:YES completion:nil]; break; case MessageComposeResultCancelled: NSLog(@"CANCELLED"); [self dismissViewControllerAnimated:YES completion:nil]; break; } }
source share