I have a view controller "Paircontroller" that presents an MFMessageComposeViewController, as so:
NSArray *recpts = [[NSArray alloc]initWithObjects:phone.text, nil];
MFMessageComposeViewController *mcontr = [[MFMessageComposeViewController alloc]init];
mcontr.body = @"Sign up for our app!";
mcontr.recipients = recpts;
mcontr.subject = @"hey!";
mcontr.delegate = self;
[self presentViewController:mcontr animated:YES completion:^{
}];
this view controller's interface looks as follows:
@interface PairViewController : UIViewController<UITextFieldDelegate,CustomIOS7AlertViewDelegate, UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate>
@end
Within the view-controller's implementation, I have defined the delegate method - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
as follows:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"unknown error sending m");
break;
case MessageComposeResultSent:
NSLog(@"Message sent successfully");
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:^{}];
}
However, the delegate method is not being called (breakpoint not hit, and NSLogs not being hit either).
Can someone help me out on why this is not working?
Thanks!
C
I think the following change should work. MFMessageComposeViewController
is a UINavigationController
subclass, so in your original code you are setting UINavigationControllerDelegate
to self.
mcontr.messageComposeDelegate = self;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.