[英]After hitting cancel in a MFMessageComposeViewController nothing happens
After though that after using MFMailComposeViewController
the move to MFMessageComposeViewController
was straight foward, but there is a catch. 虽然在使用MFMailComposeViewController
,移动到MFMessageComposeViewController
是直接的,但有一个问题。
Suppose this code: 假设这段代码:
MFMessageComposeViewController* mySMS = [[MFMessageComposeViewController alloc] init];
[mySMS setDelegate:self];
[self presentModalViewController:mySMS animated:YES];
It works this way for mails, but in sms you should set different the delegate to an internal structure like this: 它以这种方式用于邮件,但在短信中你应该将委托设置为不同的内部结构,如下所示:
[SMS setMessageComposeDelegate:self];
Hope you don not get stuck on this as I did early today. 希望你不要像今天早些时候那样陷入困境。
You need to Implement the delegate method -(void)mailComposeController(MFMailComposeViewController*)controller didFinishWithResult (MFMailComposeResult)result error:(NSError*)error:
您需要实现委托方法-(void)mailComposeController(MFMailComposeViewController*)controller didFinishWithResult (MFMailComposeResult)result error:(NSError*)error:
And inside it you should dismiss it yourself: 在它里面你应该自己解雇它:
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You can see MFMailComposeResult in Apple documentation 您可以在Apple文档中看到MFMailComposeResult
enum MFMailComposeResult {
MFMailComposeResultCancelled,
MFMailComposeResultSaved,
MFMailComposeResultSent,
MFMailComposeResultFailed
};
typedef enum MFMailComposeResult MFMailComposeResult;
And you must dismiss controller by yourself in delegate method 你必须在委托方法中自己解雇控制器
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result){
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.